Can I have my own default Exception class

  • Thread starter Thread starter Parag
  • Start date Start date
P

Parag

Hi,

I am writing error handling mechanism for a large website and one of
the requirements that has come is whether it is possible to have the
..NET application whenever it throws exception it throws a custom
defined exception. For e.g.
Default behaviour is as shown:
Try
some code
Catch Ex as Exception

End try

Can I have something like for all types of exceptions

Try
some code
Catch Ex as MyException

End try

This should be the default behaviour of my .NET application

Regards

Parag
 
Yes, you can do what you asked, you can actually have multipul catch
statements within the try to catch different types of exceptions to.

Mike Bulava
 
Parag,
In addition to Mike's comments.

To define your own exceptions simply inherit from
System.ApplicationException or System.SystemException.

You can inherit from System.Exception itself, however that is not
recommended.

You may want to consider defining MyBaseException that all your user
exceptions inherit from.

For the .NET guidelines on creating exceptions see:
http://msdn.microsoft.com/library/d.../html/cpconErrorRaisingHandlingGuidelines.asp

Hope this helps
Jay
 
Back
Top