rethrow

control structure

Syntax
rethrow


Purpose

You can use rethrow to resume a caught throw. You can only use rethrow within a catch clause. The new instance of the throw is created regardless of any other throws pending, and is dealt with in the same manner as any other throw.

The new throw has the same name and all the parameters of the original throw.

The following is an example of rethrow used with #program-error.

  declare catch division-by-zero ()
  
  define integer function 
     divide (value integer numerator,
             value integer denominator)
  as
     return numerator / denominator
  
   catch #program-error code error-code
     do when error-code = 4006
        throw division-by-zero ()
  
     else
        rethrow 
     done
  
  process
     local integer numerator   initial { 5 }
     local integer denominator initial { 0 }
  
     output "d" % numerator || " divided by " || "d" % denominator || " is: " || "d" % divide (numerator, denominator) || "%n"
  
   catch division-by-zero ()
     output "UNDEFINED!%n"

The catch of #program-error in the function body deals only with an attempt to divide by zero, and uses rethrow so that all other causes of a #program-error are rethrown and dealt with appropriately by an other catch clause, elsehwere in the program (not shown).

If a rethrow is not caught, the program will terminate.