Scilab Bag Of Tricks: The Scilab-2.5.x IAQ (Infrequently Asked Questions) | ||
---|---|---|
Prev | Chapter 7. Scilab Core | Next |
We briefly discuss how to produce the three possible classes of errors: fatal, warning, and message in Scilab.
To signal a fatal error condition in an interface procedure, call error with the appropriate code. The codes can be looked up in SCI/routines/system/error.f.
Here is a code snippet that does this.
if (ifail .eq. 2) then call error(1232) return endif
If there is no suitable error message, place you own message (length <= 80 chars) in the global variable buf, and call error afterwards.
![]() |
The string placed in buf must not be longer than 80 characters. |
if (ier .eq. 6) then buf = 'invalid limits' call error(32253) return endif
Sideffect of calling error: The Scilab stack is cleaned up, i.e. put back in the state it was just before the user routine has been entered.
On the Scilab interpreter level an error terminates the evaluation of whatever is currently evaluated (expression, file, or string), unless the trapping of errors has been modified by errcatch. See also the interpreter functions errclear, and iserror.
To signal non-fatal error conditions (also known as soft-errors, or warnings), place a negative integer in err2, and call out to display the warning message. Depending on the situation a return may be issued after that. The Scilab stack is not cleaned up, which means all return values from the interface routine are passed back normally. This is the solution of choice if the user can decide how to proceed, based on the return values.
Again, here is a small piece of code for demonstration.
if (fail .eq. 1) then err2 = -6343 call out('reached table limit') return endif
On interpreter level it is now mandatory to call iserror after a call to a routine that issues warnings like this. In the user-level error handler the error code must be reset by errclear to allow for further warnings to be received.
A typical way of coping with these soft-errors in the interpreter level is shown in Example 7-4.
Messages are the least severe class of errors. Sometimes they are not really errors, but just additional information that something unexpected is going on. No news is good news.
We have already seen the appropriate subroutine in action. It is out.
if (iter .gt. 1000) then call out('iterating excessively') endif