WinForms: Custom Exceptions & Global Exception Handlers

This solution demonstrates two more advanced exception mangement techniques. 

Featured Highlights

This sample contains two projects: a Windows Forms client and a Class Library.

Class Library

The class library defines one application class, Customer. In addition it exposes a set of custom exception class which are used to expose application defined errors. Unlike previous versions of Visual Basic (and COM which it was based upon), .NET Exceptions are fully typed removing the need for error numbers. While you can still have error numbers, it is much better to defined application exceptions which can expose a much richer array of information to the caller. In this application there is a hierarchy of exceptions. At the top is CRMSystemException for the fictitious SomeCompany CRM system. It inherits from System.Application exception (as opposed to System.SystemException which is used by Microsoft). From there, two classes inherit from it:

There is nothing in this sample related to employees, but we wanted to show how you can have a larger product that could be made up of various modules or components. There then two more exceptions which both inherit from CustomerException:

Each class exposes different levels of information and functionality. Examine the source code for more comments. Note that your exceptions classes can be named anything, but by convention they should end with the suffix Exception.

Requirements

Requires the Trial or Release version of Visual Studio .NET Professional (or greater).

Running the Sample

You need to run the Client application. Please see that ReadMe file.

Last Update: 16 July 2002