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# Basics (Retired) Perfect Final

C# Basic final

for some reason i am getting this message:

Program.cs(32,12): error CS1524: Unexpected symbol }', expectingcatch' or `finally' Compilation failed: 1 error(s), 0 warnings

I dont know whats wrong with it?

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
            var count = 0;

            while (true)
            {
                Console.Write("Enter the number of times to print \"Yay!\": ");

                var input = Console.ReadLine();

                try
                {
                    var inputTimes = int.Parse(input);

                    if (inputTimes <= count)
                    {
                        Console.WriteLine("That is not enough for A Yay!");
                        continue;
                    }

                    for (int i = 1; i <= inputTimes; i++)
                    {
                        if (i <= inputTimes) 
                        Console.Write("Yay!");
                    }
                }

            }
        }
    }
}

1 Answer

Seth Kroger
Seth Kroger
56,403 Points

You need at least one catch block for any try block so exceptions can be caught instead of falling through and potentially stopping the program.

try {
.....
} catch (SomeExeception e) {
.....
}