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 trialbosco dsa
12,599 PointsHaving 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) {
Console.WriteLine("Yay!");
doIt-=1;
}
}
catch (SystemException) {
Console.WriteLine("You must enter a whole number.");
continue;
}
break;
}
}
}
}
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi 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.
bosco dsa
12,599 Pointsbosco dsa
12,599 Pointsthanks