Visual Basic 2010 – Custom Exceptions Sample

0 comments

Posted on 3rd May 2010 by Admin in Visual Basic 2010

, ,

This sample contains two projects: a Windows Forms client and a class library.

Class Library (Server)

The class library defines theCustomerand a set of custom exception classes that are used to expose application-defined errors. The exception classes are related by an inheritance hierarchy. The base class isCRMSystemException, which inherit fromApplicationException.CustomerExceptionandEmployeeExceptioninherit fromCRMSystemException. There are two more exceptions which inherit fromCustomerException:CustomerNotFoundExceptionandCustomerNotDeletedException.Each class exposes different levels of information and functionality.

Client Code

The client application has a reference to the class library. Two command buttons execute methods against theCustomerclass and catch the custom exceptions. A third command button causes an unhandled exception. In addition, there is a check box labeled “Turn on Global Exception Trap” that enables a global exception trap. When enabled, the code defined in theOnThreadExceptionmethod will be executed instead of the default Windows Forms handler.

Download Project