![]()
Handling errors with catch and catchQuiet
The catch statement evaluates an expression and returns true if the expression causes an error, but does not stop the script (as an error outside a
catchwould).This lets you test the execution of an assignment or command in an
ifstatement and run error handling code ifcatchreturns true.int $divisor = 0; if ( catch ($factor = 42/$divisor) ) { print "Attempt to divide by zero caught\n"; }When MEL encounters the divide by zero error inside the
catchstatement, it automatically prints an error message but does not stop execution. Thecatchstatement returns true and so theifstatement executes the block.To catch an error without having MEL automatically print an error, use the catchQuiet statement instead of
catch.