#898 – Using Code Snippets to Implement a Custom Exception Type

Visual Studio includes a code snippet that makes it easier to implement a custom exception type.

To add a custom exception type using a code snippet, start by adding a new class file to your project and naming it to match your exception type.

898-001

898-002

 

In the new class, delete the class definition, so that all that remains in the file is a namespace definition.

898-003

 

Create a new blank line within the namespace definition.  Begin typing the word “exception” and look for the icon in the Intellisense dropdown that indicates a code snippet.

898-004

 

Press the TAB key twice so that the code snippet is inserted.  The definition of a new class that derives from Exception will be inserted.

898-005

 

While the name of the new class is highlighted, type the name of your new exception type and press TAB.  The new exception type name will be inserted where appropriate.

898-006

 

Advertisements