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 Throwing Exceptions

drstrangequark
drstrangequark
8,273 Points

Compiler saying I have an error on a document that I don't have access to

This challenge asks me to check if a value is more than 0 and less than 20 and to throw a System.Exception if it's outside that range.

I think that my code is correct but the compiler is saying there is a missing ; on StudentCode.cs, which must be hidden from the challenge because I don't have access to it.

Is there something wrong with my code here?

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

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

if(value < 0 || value > 20)
{
    throw new System.Exception;
}

1 Answer

andren
andren
28,521 Points

The issue is that you have forgotten to place parenthesis after Exception on this line:

throw new System.Exception;

When you throw an exception you make a new instance of an exception class, and just like when you make an instance of any other class you have to call the class constructor using parenthesis.

Like this:

if(value < 0 || value > 20)
{
    throw new System.Exception();
}