Error Checking and Branching

The MaxL Perl Module is the most powerful way to integrate error handling into MaxL. However, the following method is for users who do not implement the MaxL Perl Module.

IfError instructs the MaxL Shell to respond to an error in the previous statement by skipping subsequent statements, up to a certain location in the script that is defined by a label name.

IfError checks the presence of errors only in the precedent statement. IfError checks for:

Goto forces the MaxL Shell to branch to a certain location in the script defined by a label name; goto is not dependent on the occurence of an error.

Syntax

iferror LABELNAME
goto LABELNAME
define label LABELNAME

Example: Iferror (MaxL)

The following example script contains a dimension build statement and a data load statement. If the dimension build fails, the data load is skipped.

login $1 $2;

import database sample.basic dimensions
 from data_file 'C:\\data\\dimensions.txt'
 using rules_file 'C:\\\\data\\rulesfile.rul'
 on error append to 'C:\\\\logs\\dimbuild.log'; 
 
iferror 'dimbuildFailed';

import database sample.basic data from data_file 
"$ARBORPATH\\app\\sample\\basic\\calcdat.txt" 
 on error abort; 

define label 'dimbuildFailed';
exit;

Example: Iferror (MaxL Shell)

The following example script tests various errors including MaxL Shell errors, and demonstrates how you can set the exit status variable to a nonzero argument to return an exit status to the MaxL Shell.

###  Begin Script ###

login $1 $2;
echo "Testing syntactic errors...";

spool on to spool.out;

set timestampTypo on;
iferror 'End';

echo "Testing shell escape...";
shell "cat doesnotexist.txt";
iferror 'ShellError';

msh "doesnotexistlerr.mxl";
iferror 'FileDoesNotExistError';

echo "Script completed successfully...";
spool off;
logout;
exit 0;


define label 'FileDoesNotExistError';
echo "Error detected: Script file does not exist";
spool off;
logout;
exit 1;

define label 'ShellError';
echo ' Shell error detected...';
spool off;
logout;
exit 2;

define label 'End';
echo ' Syntax error detected...';
spool off;
logout;
exit 3;

###  End Script ###

Example: Goto

The following example script contains a dimension build statement and a data load statement. Goto is used to skip the data load.

login $1 $2;

import database sample.basic dimensions
 from data_file 'C:\\data\\dimensions.txt'
 using rules_file 'C:\\\\data\\rulesfile.rul'
 on error append to 'C:\\\\logs\\dimbuild.log'; 
 
goto 'Finished';

import database sample.basic data from data_file 
"$ARBORPATH\\app\\sample\\basic\\calcdat.txt" 
 on error abort; 

define label 'Finished';
exit;

Notes

The MaxL Shell will skip forward in the script to LABELNAME but not backwards.