Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Philip Jensen](https://uploads.teamtreehouse.com/production/profile-photos/1557672/micro_avatar.jpg)
Philip Jensen
7,341 Pointsnot sure how to tackle this problem after a few tries. where should the try and catch start within the code
the code is below and have to ensure whole numbers are used and anything else is an invalid entry.
I tried rewatching the video but i am stuck on the placement of the try and catch and what goes where in general.
below is how completed the 1st task without any issues.
appreciate any help
using System;
namespace Treehouse.CodeChallenges { class Program { static void Main() { Console.Write("Enter the number of times to print \"Yay!\": "); int counter = 0; String times = Console.ReadLine(); int totals = int.Parse(times); while (counter < totals) { Console.Write("\"Yay\"! "); counter = counter + 1; }
}
}
}
using System;
namespace Treehouse.CodeChallenges
{
class Program
{
static void Main()
{
Console.Write("Enter the number of times to print \"Yay!\": ");
int counter = 0;
String times = Console.ReadLine();
int totals = int.Parse(times);
while (counter < totals)
{
Console.Write("\"Yay\"! ");
counter = counter + 1;
}
}
}
}
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsHere's a few hints:
- the line that has the int.parse will go inside the try block, since that's what you are testing
- the lines that use the converted value can also go inside the try block
- the catch block comes after the try block, and will contain the code to print the error message
Hopefully, that will get you going. Happy coding! -sp
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsI guess you fixed it while I was composing my answer. Congrats, and good job!
Philip Jensen
7,341 PointsPhilip Jensen
7,341 Pointsmust be very tired i managed to solve it :)
using System;
namespace Treehouse.CodeChallenges { class Program { static void Main() {
}