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

Tomasz Necek
PLUS
Tomasz Necek
Courses Plus Student 7,028 Points

C# catch(FormatExeption)

Program.cs(16,20): error CS0246: The type or namespace name `FormatExeption' could not be found. Are you missing an assembly reference? Why?:) What can I do? Thank you very much!

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {
        Console.Write("Enter the number of times to print \"Yay!\": ");
        int number = Int32.Parse(Console.ReadLine());

           for(int i = 0; i < number; i++)

             try
              {
               number = Int32.Parse(Console.ReadLine()) ;
              }
             catch(FormatExeption)
              {
                Console.WriteLine("You must enter a whole number");
                continue; 
              }
              {
             Console.WriteLine("Yay!");
              }

           }
    }
}

3 Answers

Steven Parker
Steven Parker
231,269 Points

You got most of the parts there, but it looks like you have a few issues:

  • FormatException must be spelled with a "c"
  • you accidentally placed your try...catch blocks in between your for and its block
  • since you assign number inside the try now, you won't assign it where you declare it
  • the catch is not (and will not be) inside the loop, so you'll need a return instead of a continue

Fix those up and you should be good.

saranyamoellers
saranyamoellers
31,691 Points

adding this line on top-> using System.Runtime.Serialization;