#897 – Rules for Creating a Custom Exception Type

The basic guidelines for defining your own custom exception types are as follows:

  • Derive from one of the following:
  • End the name of your type with “Exception”  (e.g. InvalidDogBarkException)
  • Mark your exception type as Serializable
  • Define the following constructors:
    • public MyException()
    • public MyException(string message) : base(message)
    • public MyException(string message, Exception inner) : base(message, inner)
    • public MyException(SerializationInfo info, StreamingContext context) : base(info, context)
  • Consider adding custom data:
    • Add one or more custom properties
    • Add one or more constructor that accept values for the custom properties

Click here for a full example.

 

 

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #897 – Rules for Creating a Custom Exception Type

  1. Pingback: Dew Drop – July 29, 2013 (#1,594) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: