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#

Mark Libario
Mark Libario
9,003 Points

Unexpected Symbol catch { I dont know whats wrong..

I dont understand how to solve this error:

Program.cs(34,16): error CS1525: Unexpected symbol `catch'
Program.cs(35,16): error CS1525: Unexpected symbol `{'
Program.cs(40,8): error CS1524: Unexpected symbol `}', expecting `catch' or `finally'
Compilation failed: 3 error(s), 0 warnings
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {

           Console.Write("Enter the number of times to print \"Yay!\": ");
           string printYay = Console.ReadLine ();
           var printCounter = 0.0;

            try
            {
            int celebrate = int.Parse(printYay);
                if (celebrate < 1) 
              {
                Console.WriteLine ("You need to print at least one.");

              }


              while (true)
              {
                Console.WriteLine ("Yay!");
                printCounter += 1;



                if (celebrate == printCounter)
                {
                  break;
                }
            }
                catch (FormatException)
                {
                    Console.WriteLine ("You must enter a whole number.");
                    continue;
                }
            }
        }
    }
}

1 Answer

Simon Owerien
Simon Owerien
12,829 Points

There is a '}' missing in your code to close the 'try-block'.