Previous

Next


You can create (or throw) an exception by using the keyword Throw

Throw New System.Exception 



General Catch Statement

Try 

Catch e As System.DivideByZeroException
   ex.Message -
   ex.InnerMessage -
Finally
End Try




Dedicated Catch Statements

Try 

Catch e As System.DivideByZeroException

Catch e As System.ArithmeticException

Catch e As System.Runtime.InteropServices.ComException

Catch

Finally
End Try



COM Exception Catch

Try 

Catch e As System.Runtime.InteropServices.ComException

Catch

Finally
End Try


Finally

Any code in the Finally block is guaranteed to be executed regardless of whether an exception is thrown
A finally block can be created with or without catch blocks



Creating your own exceptions

They must derive (directly or indirectly) from the System.ApplicationException


Public Class MyCustomException 
   Inherits System.ApplicationException

   Public SUb New(ByVal message As String)
      MyBase.New(message)
   End Sub
End Class



InnerException Property

You may want your catch block to take some corrective action first and then rethrow the exception to the outer try block
You may want to refer to the exception history and InnerException property of an exception retrieves the original/previous exception.




Previous

Next


© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited