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

cindy yuan
cindy yuan
1,143 Points

Not sure what I did wrong...

Not sure if I'm missing something here, it says when 2 is entered it throws an exception....what did I miss out?

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

if(value <0 || value >20)
    {
    Console.WriteLine(string.Format("You entered {0}",value));
    }
    else
    {
    throw new System.Exception("Value is outside of the range.");
    }

1 Answer

Your statements are reversed. if(value <0 || value >20) you want to throw the exception.

cindy yuan
cindy yuan
1,143 Points

Aww got it thank you!