The Raise Statement

The Raise statement raises an exception.

raise-statement:

Raise   expressionopt

The Raise statement with the specified expression raises 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 raised.

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 raised, the control is transferred to the first Except block in one of the Try enclosing statements that can handle this exception. The process executed after raising an exception and before the control is transferred 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 raising point is location in the program where the exception was raised.

Example

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

See also:

Jump Statements