A program indicates that an error condition has occurred by executing a Throw
statement. The statement "throws" an object of a type derived from System.Exception
that provides information about the error that has occurred. If the expression does not evaluate to an instance of a type derived from System.Exception
, then an error occurs at compile time. If at runtime the expression evaluates to Nothing
, then a System.NullReferenceException
object instance is thrown instead.
Structured error handling is done through a Try
statement. Exceptions thrown by the Throw
statement can be "caught" in a Try
statement. Execution of a Try
statement begins with the first statement in the try block. It is illegal to explicitly transfer execution into a try block except from a catch block.
A Throw
statement may omit the expression within a catch block of a Try
statement. In that case, the statement "rethrows" the current exception currently being handled within the catch block.
Throw
[ Expression ] StatementTerminatorTry
StatementTerminatorEnd
Try
StatementTerminator