Raising Custom Errors

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

I want to raise custom errors. For instance, when my File class tries to
copy a file, I check to make sure the file is available (by trying to get an
exclusive lock on it). I try for a specific period of time, and if the file
doesn't become available I want to throw an error stating something like
"File not available".

Since I will be re-using this functionality (of throwing custom errors) I'd
like to create a class. Anyone got any code implementing something like
this? Most of the stuff I've found on the web seems to inherit the
system.exception class, but some people recommend applicationexception.

Any code or insight appreciated.
 
Jason,

You should inherit from System.ApplicationException. You can then override
the Message property.

If you are just interested in throwing an exception with a particular
message, you can throw an ApplicationException and supply the message:

Throw New ApplicationException ("my message")

Kerry Moorman
 
Back
Top