The Raise Statement

The Raise statement throws an exception.

raise-statement:

Raise   expressionopt

The Raise statement with the specified expression throws an exception with the value obtained as a result of calculating the expression. This value must represent an instance of the object type, which matches or derives from System.Exception. If the result of calculating the expression is Null, System.NullReferenceException is thrown.

The Raise statement without the specified expression can be used only within the exception handler in the Except block of the Try statement. In this case it continues handling (that is, further throwing) the current exception that is being handled at the moment.

When an exception is thrown, the control is passed to the first Except block in one of the Try enclosing statements that can handle this exception. The process executed after throwing an exception and before the control is passed to an appropriate handler is named throwing an exception. Throwing an exception consists of repeating the following steps until an appropriate handler is found. In this description the throwing point is location in the program where the exception was thrown.

Example

Private Sub TestRaise();
Begin
    Try
        //Error generation
        Raise New Exception("Execution error!");
    Except On Ex: Exception Do
        //Error handling
    Finally
    End Try;
End Sub;

See also:

Jump Statements