UDI has a very robust error detection/reporting mechanism. For many common programming errors, the UDI messages are so detailed that the user does not need to resort to a source code debugger.
When UDI detects an error,
one or more messages are printed and an error is signaled.
The error signal can be caught in the user's program with the
ERRORCATCH",
ON_ERROR", and
ENDCATCH" macros.
Normally, only the code between theSPMquot
ERRORCATCH"
- Normal processing code -SPMquot
ON_ERROR"
- Error processing code -ENDCATCH"
SPMquot
ERRORCATCH" and SPMquot
ON_ERROR"
keywords is executed. If UDI signals an error, however, the code between
the SPMquot
ON_ERROR" and SPMquot
ENDCATCH" keywords is executed. Note that
SPMquot
ON_ERROR" is optional; if an error is signaled and it is absent,
execution
resumes after the SPMquot
ENDCATCH".
The example program in Figure 2.2 will not run correctly
because the element type of result"
is not the same as the element type of
vector1" and
SPMquot
vector2".
When the program is run, we get the following output:
% example vmul: the data type of 'result' must be equal to real. OOPS! Detected an error %If the user has not used the
SPMquot
ERRORCATCH" mechanism and UDI signals an
error, the
abort()" routine is called which causes a core dump (on Unix
systems) to aid in debugging. The user can specify a different
routine by calling
error_handler(fptr)" where fptr is a pointer
to a function returning an integer (
int (*fptr)()"). Note that the
error handling routine should eventually call
exit()" since it is not
possible to recover from most UDI errors.