Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Raising Custom Errors

Status
Not open for further replies.

jasonp45

Programmer
Aug 23, 2001
212
US
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.
 
From the MSDN Help file on ApplicationException
ApplicationException is thrown by a user program, not by the common language runtime. If you are designing an application that needs to create its own exceptions, derive from the ApplicationException class. ApplicationException extends Exception, but does not add new functionality. This exception is provided as means to differentiate between exceptions defined by applications versus exceptions defined by the system.

I have an application where I have to generate custom errors and I've found that inheriting from ApplicationExcpetion provides me with everything I need. Quick example:

Code:
Public Class MyCustomException
    Inherits System.ApplicationException

    ' constructor that overloads the base constructor for ApplicationException
    Sub New(ByVal msg As String)
        Me.New(msg, errorType, True, True, 0)
    End Sub

    ' insert other constructors/methods etc.
End Class

   ' later on in the code
   Throw New MyCustomException("This is a custom exception")

Jay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top