Wednesday, March 5, 2008

Exception Handling in VB.

_____________________________________________

Exception Handling in VB.

_____________________________________________

' Throw an exception
Dim ex As New Exception("Something is really wrong.")
Throw ex

' Catch an exception
Try
y = 0
x = 10 / y
Catch ex As Exception When y = 0 ' Argument and When is optional
Console.WriteLine(ex.Message)
Finally
Beep()
End Try

' Deprecated unstructured error handling
On Error GoTo MyErrorHandler
...
MyErrorHandler: Console.WriteLine(Err.Description)

____________________________________________________________________

Note:Applicable for .net also asp.net.
____________________________________________________________________

No comments: