Database Reference
In-Depth Information
Exploring the Type, Message, and StackTrace Properties of an
Exception
Any .NET exception that occurs in Visual Studio or by running the EXE file is full of information to let the
developer either handle it or investigate further. The Type, Message, and StackTrace properties serve
this great purpose.
Type defines the category, or what kind of exception occurred. Whenever a .NET exception occurs, it
shows the type of exception in the title bar of the dialog. As you can see, FileNotFoundException is
mentioned on the title bar of the dialog in Figure-11-8.
You can find more information about any exception by clicking View Detail toward the bottom
(under Actions) of the dialog, as shown in Figure 11-7. This applies to any exception you encounter
within .NET.
Once you click View Detail, you will see another window open; it provides the exception snapshot.
Expand this, and you will find a lot of information. Look for the Message property, which holds the exact
message that your exception occurred with, as shown in Figure 11-9.
In most cases, developers want to add some extra text with this system-generated message. We
cover how to do so later in this chapter.
Figure 11-9. Exception's Message property
Other important information is exposed by the StackTrace property, which is mainly useful for
people who want to debug the code and find out which line is actually causing the problem. Also, many
organizations log such information into the Event Viewer or log files for their monitoring purposes.
Just below the Message property, you will find the StackTrace option; select it and then click the
arrow pointing down on the right side of its description text, as shown in Figure 11-10.
 
Search WWH ::




Custom Search