Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Objects Inheritance Catching Exceptions

Not 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));

 value < 0 || value > 20;
    Console.WriteLine("out of bounds");

1 Answer

Steve Agusta
Steve Agusta
6,220 Points

Here 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.