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 trialRajmohan Ganapathi
1,405 PointsIn the Program.cs file, write code to check if the value integer is less than 0 or greater than 20. Throw System.Excepti
In the Program.cs file, write code to check if the value integer is less than 0 or greater than 20. Throw System.Exception if the value is outside of the range.
int value = int.Parse(Console.ReadLine());
Console.WriteLine(string.Format("You entered {0}",value));
try
{
if(value <0 || value >20)
{
throw System.Exception;
}
}
catch(Exception)
{
Console.WriteLine("value not in the permissible range");
}
4 Answers
Steven Parker
231,198 PointsYou're working too hard on this one! The instructions only ask you to perform the test and throw the exception. You won't need a "try", "catch" or error message code for this challenge.
Jennifer Ward
8,458 Points''' int value = int.Parse(Console.ReadLine());
{ if(value < 0 ||value > 20) { throw new System.Exception(); } } { Console.WriteLine(string.Format("You entered {0}",value)); } '''
is what finally worked for me. I got stuck on this for wayyyyy too long using try/ catch
Jude Brown
Courses Plus Student 629 PointsLOL - I did exactly the same thing. Back to the drawing board.
Sara Rena Anderson
15,045 Pointsint value = int.Parse(Console.ReadLine());
if(value < 0 || value > 20) { throw new System.Exception(); }
Console.WriteLine(string.Format("You entered {0}",value));