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

Daniel Hunter
Daniel Hunter
4,622 Points

syntax error code - StudentsCode.cs(13,4): error CS1525: Unexpected symbol `Console'

I can't understand why its saying console is an unexpected symbol. why would it work on line 7 but not on line 13? I've tried looking at other examples of try/catch statements and as far as I can tell you can use 'Console' in the catch block. please can anyone give me an idea as to what I'm doing wrong. Thanks

Dan

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

try 

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

catch (Exception)

{
    Console.WriteLine("Value is out of bounds!"); 
}

3 Answers

Steven Parker
Steven Parker
231,269 Points

I agree that the compiler message is a bit confusing, but what's happened is that the "if" and the "throw" that were originally part of the code somehow got stripped away leaving only the inner conditional expression from the "if" and causing a syntax error.

Replace the original code inside your new wrapper and you should pass.

Daniel Hunter
Daniel Hunter
4,622 Points

thanks Steven, I originally tried to wrap the if statement as you said but I think I put the if statement before the curly braces in the try block. I almost have it right now but it still won't pass. I don't have any syntax errors but I'm now getting a message saying " Bummer! I entered "25" but nothing was printed out. Make sure to write the message to the console." I'll probably kick myself when I find it but I just can't work out why that doesn't pass.

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

try { if (value > 0 && value < 20) { Console.WriteLine(string.Format("You entered {0}",value)); } }

catch (Exception) { Console.WriteLine("Value is out of bounds!"); }

Daniel Hunter
Daniel Hunter
4,622 Points

As soon as I posted my reply I figured it out! I needed to put Console.WriteLine in an else statement in the try block and it passed. thanks Steven