O'Reilly logo

Pro C# 2010 and the .NET 4 Platform, Fifth Edition by Andrew Troelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.9. The Result of Unhandled Exceptions

At this point, you might be wondering what would happen if you do not handle an exception thrown in your direction? Assume that the logic in Main() increases the speed of the Car object beyond the maximum speed, without the benefit of try/catch logic:

static void Main(string[] args)
{
    Console.WriteLine("***** Handling Multiple Exceptions *****\n");
    Car myCar = new Car("Rusty", 90);
    myCar.Accelerate(500);
    Console.ReadLine();
}

The result of ignoring an exception would be rather obstructive to the end user of your application, as an "unhandled exception" dialog box is displayed (see Figure 7-3).

Figure 7.3. The result of not dealing with exceptions

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required