Jump to content

Exceptions: Difference between revisions

Visual basic
(Visual basic)
Line 652:
[myproc] [puts] catch
=[new error 1 2 3]
 
=={{header|Visual Basic .NET}}==
 
===Defining exceptions===
Class MyException
Inherits Exception
'data with info about exception
End Class
===Throw exceptions===
Sub foo()
Throw New MyException
End Sub
 
===Catching exceptions===
Sub bar()
Try
foo()
Catch e As MyException When e.Data.Contains("Foo")
' handle exceptions of type MyException when the exception contains specific data
Catch e As MyException
' handle exceptions of type MyException and derived exceptions
Catch e As Exception
' handle any type of exception not handled by above catches
Finally
'code here occurs whether or not there was an exception
End Try
End Sub
Cookies help us deliver our services. By using our services, you agree to our use of cookies.