Using the raise_ Method

To raise user exceptions, use the raise_ method in the ExceptionClass class. (ExceptionClass is a subclass of the Class class in the Type parent class.) The raise_ method has the following syntax.

exception-class-name.raise_(errorCode: Integer;
                            errorItem: String);

The raise_ method automatically creates an exception of type exception-class-name and assigns the specified errorCode and errorItem properties before the exception is issued.

The following example shows a method that raises an exception of type NormalException with an error code of 55 and a description of "Invalid Company".

initCompany(newCompany: Company io);
begin
    if newCompany = null then
        NormalException.raise_(55, "Invalid Company");
    endif;
    ... // perform the rest of the initialization logic
end;

The following example shows a method used to raise an exception of type GraphException when two arrays contain a different number of entries.

checkForErrors(array1: StringArray; array2: IntegerArray);
begin
    if array1.size <> array2.size then
        GraphException.raise_(3, "Arrays are the wrong size");
    endif;
end;

The GraphException class in this example is a user-defined Exception subclass created for the application.