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

Get Pro C# 2010 and the .NET 4 Platform, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.