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

jack Sandberg
jack Sandberg
1,659 Points

So something must be wrong here .. "Bummer! I entered "2". I expected "You entered 2" but got " You entered 2". "

It is exactly the same sentence ..

Program.cs
int value = int.Parse(Console.ReadLine());
if ( value < 0 || value > 20){

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

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! Kyler Smith is correct. You must remove the space. But the reason that your code isn't working after you remove the space is because the challenge explicitly asks you to throw an exception. So inside your if statement you need to throw an exception using this line:

    throw new System.Exception("Value not in range.");

If you make both the changes mentioned, it should pass. Hope this helps! :sparkles:

Kyler Smith
Kyler Smith
10,110 Points

It looks like there is a space in front of your answer. Try removing it and see if that fixes your problem. Good luck!

else{
Console.WriteLine("You entered " + value);
}
jack Sandberg
jack Sandberg
1,659 Points

Thanks for the help but that did not work :(

Kyler Smith
Kyler Smith
10,110 Points

You need to throw an exception if the number is not between 0 and 20.

int value = int.Parse(Console.ReadLine());
if ( !(value > 0) || !(value < 20)){
    throw new System.Exception();
} else {
Console.WriteLine("You entered " + value);
}