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

bosco dsa
bosco dsa
12,599 Points

Having trouble with catching the exception on the final challenge

It says "Bummer. Try again." When I run it in workspaces it works perfectly.

using System;

namespace Treehouse.CodeChallenges
    class Program
        static void Main()
            while (true) {
                try {
                    var doIt=Int32.Parse(Console.ReadLine());
                    Console.Write("Enter the number of times to print \"Yay!\": ");
                    while (doIt!=0) {
                catch (SystemException) {
                    Console.WriteLine("You must enter a whole number.");


1 Answer

Hi Bosco,

For this challenge you don't need a loop. So you can take out the while, break, and continue statements. The program should just end if they don't enter a number rather than continually prompt for a number.

The other issue is that you should be a catching a FormatException

I'm not sure if it will affect the challenge but the ReadLine should be after the Write so that the user knows what they're supposed to enter.