Define your own exception?

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

Is there any way to define your OWN exception in a form or a class? I.E. If
you wanted to define a NoDataFoundException so you could do a: Throw
NoDataFoundException.

Is this possible? And if so, how would you go about defining this? I see
lots of articles on using Try..Catch but nothing really on defining your own
exceptions.

Thanks.

Tom
 
* "Tom said:
Is there any way to define your OWN exception in a form or a class? I.E. If
you wanted to define a NoDataFoundException so you could do a: Throw
NoDataFoundException.

Is this possible? And if so, how would you go about defining this? I see
lots of articles on using Try..Catch but nothing really on defining your own
exceptions.

\\\
Public Class NoDataFoundException
Inherits Exception
 
Hi,

Create a class that inherits from exception.

Public Class NoDataFoundException
Inherits Exception

End Class

Ken
----------------------
 
Tom said:
Is there any way to define your OWN exception in a form or a class? I.E. If
you wanted to define a NoDataFoundException so you could do a: Throw
NoDataFoundException.

Is this possible? And if so, how would you go about defining this? I see
lots of articles on using Try..Catch but nothing really on defining your own
exceptions.

Like this

Public Class NoDataFoundException
Inherits System.Data.DataException
Public Sub New(ByVal Message As String)
MyBase.New(Message)
End Sub
Public Sub New(ByVal Message As String, ByVal InnerException As Exception)
MyBase.New(Message, InnerException)
End Sub
End Class

You can, of course, add additional information to the exception by adding
instance fields, etc.

David
 
Back
Top