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)
![Tony Lawrence](https://secure.gravatar.com/avatar/9f60c917b4d743862b3cef3140c9ec1b?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Tony Lawrence
3,056 PointsTrouble with the Challenge identifying catch statement.
Sorry to intrude again. I'm having trouble figuring out where to put the catch method in order to make format exceptions. Though I'm concerned that the challenge will have trouble with me changing the code to where it states that I'm failing to the first challenge. I'm getting errors stating that there is no enclosing loop to break or continue or it fails to recognize my catch statement.
This what I have so far:
using System;
namespace Treehouse.CodeChallenges { class Program { static void Main() { Console.Write("Enter the number of times to print \"Yay!\": ");
string input = Console.ReadLine();
var redo = int.Parse(input);
try {
while (redo != 0)
{
Console.WriteLine("Yay!");
redo -= 1;
}
if (redo == 0)
{
break;
}
}
catch (FormatException)
{
Console.WriteLine("You must enter a whole number.");
continue;
}
}
}
}
I'm wondering if I now have to reformat to make the while loop be (true) or not.
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsBe careful about where you put your try block.
In particular, you'll want the line with the int.Parse to go inside the try block so it can detect any problems converting the value.
Also, people often over-think this one and get too creative, as with any challenge it's good to keep things simple. Here are a few hints for success:
- Your program must ask for and accept input ONE TIME ONLY
- If the input validates, your program will perform exactly as in Task 1
- If the input does not validate, it will print the error message and exit
- Validation must be done by exception catching. There are other perfectly good methods that can be used for validation, but they will not pass this challenge