CHAPTER 7 UNDERSTANDING STRUCTURED EXCEPTION HANDLING
if (e.Data != null)
{
foreach (DictionaryEntry de in e.Data)
Console.WriteLine("-> {0}: {1}", de.Key, de.Value);
}
}
With this, here’s the final output you’d see:
***** Simple Exception Example *****
=> Creating a car and stepping on it!
Jamming...
=> CurrentSpeed = 30
=> CurrentSpeed = 40
=> CurrentSpeed = 50
=> CurrentSpeed = 60
=> CurrentSpeed = 70
=> CurrentSpeed = 80
=> CurrentSpeed = 90
*** Error! ***
Member name: Void Accelerate(Int32)
Class defining member: SimpleException.Car
Member type: Method
Message: Zippy has overheated!
Source: SimpleException
Stack: at SimpleException.Car.Accelerate(Int32 delta)
at SimpleException.Program.Main(String[] args)
Help Link: http://www.CarsRUs.com
-> Custom Data:
-> TimeStamp: The car exploded at 5/12/2012 9:02:12 PM
-> Cause: You have a lead foot.
***** Out of exception logic *****
The Data property is very useful in that it allows us to pack in custom information regarding the
error at hand, without requiring the building of a brand-new class type to extend the Exception base
class. As helpful as the Data property may be, however, it is still common for .NET developers to build
strongly typed exception classes, which handle custom data using strongly typed properties.
This approach allows the caller to catch a specific exception-derived type, rather than having to dig
into a dat 6