RAISE Option

 

RAISE option signals that, in case of an exception, the problem should be handled not by the local function, but by the calling one.

It means that if an exception happens during a function execution after the WHENEVER [ANY] ERROR RAISE statement was encountered, the function execution terminates and the program control returns to the calling routine, i.e., to the statement following the CALL statement. If the calling routine does not contain an error handler, the error is passed further to the parent function.

The RAISE option can be effectively used with the TRY...CATCH statement.  You can place the CALL statement to the TRY block and the RAISE option to the invoked function. If any error occurs during the function execution, the program control will pass to the CATCH block:

 

MAIN

  TRY

    CALL do_exception(100, 0)

  CATCH

    CALL foo()

  END TRY

END MAIN

 

FUNCTION do_exception(a, b)

     DEFINE a, b, c INTEGER

     WHENEVER ANY ERROR RAISE

     RETURN a / b

END FUNCTION

 

FUNCTION foo()

     DISPLAY "Exception caught, status: ", STATUS

END FUNCTION

 

RAISE action cannot be performed in the REPORT program block.