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# 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,413 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) {
.....
}