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

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,558 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();
}