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 catch would).

This lets you test the execution of an assignment or command in an if statement and run error handling code if catch returns 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 catch statement, it automatically prints an error message but does not stop execution. The catch statement returns true and so the if statement executes the block.

To catch an error without having MEL automatically print an error, use the catchQuiet statement instead of catch.