Exceptions Are Objects

One question is how errors are represented in the world of exceptions. Given that the Common Language Runtime (CLR) is an object-oriented platform, the answer is pretty obvious: objects. We won’t look at how to define exception types of our own just yet but will instead focus on the essence of such a type and look at how exceptions can be thrown and caught.

Exceptions are subtypes of a class called System.Exception, which defines the following useful members (see Figure 8.1). (I’ve omitted a few irrelevant details for now.)

Image

FIGURE 8.1 Most relevant members of the Exception base type.

One key piece of information about an ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.