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 trialR S
2,255 PointsNot sure how to make the logic in the try block throw an error and land up in the catch block
I am not sure what i am supposed to be putting in the try block to cause the program to error out and land up in the catch block
int value = int.Parse(Console.ReadLine());
Console.WriteLine(string.Format("You entered {0}",value));
try
{
value < 0 || value > 20;
}
catch(Exception)
{
Console.WriteLine("out of bounds");
}
1 Answer
Steve Agusta
6,221 PointsHere is a hint that should help you:
instead of using a try catch, you can check if the value is out of range by using an if statement, and throw the exception if the statement evaluates to true. Using a try catch will not catch an exception in this case because it's not a system exception that's being caught, it's just a value that is outside of the range that you would like it to be.