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

C# C# Objects Inheritance Throwing Exceptions

Jan-Morten Reiners
Jan-Morten Reiners
1,236 Points

Hi There, I think my Code is correct. I throw a new Exception, if the value is out of Range.

Pls have a look to my Program.cs i dont know what is wrong. I throw a new Exception and catch they with a Console.WriteLine Thank you

Program.cs
int value = int.Parse(Console.ReadLine());

try 
{
    if (!(value <= 20 && value >= 0))
    {
      throw new System.Exception();

    }
    else
    {
        Console.WriteLine(string.Format("You entered {0}",value));
    }

}
catch (System.Exception)
{
        Console.WriteLine("Wrong Range");

}

2 Answers

Steven Parker
Steven Parker
231,248 Points

You did a bit too much!

What you did was very practical, but this challenge only wanted you to throw the exception, not catch it. I'd guess the tester evaluates your work by catching it itself.

Just remove your try and the entire catch block and you should pass.

Jan-Morten Reiners
Jan-Morten Reiners
1,236 Points

Thanks ! :) the next step was to add the try/catch :D