Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
error
reports a run time error
Syntax
error(message) error(message, n) error(n, message)
Arguments
- message
Vector of strings. The error message to be displayed. Each component is displayed on a separate line. Providing an error message translated with
gettext(…)
is a good practice.- n
integer > 0: numerical identifier ascribed to the error. Default = 10000. While the message is often translated into the current session language,
n
allows to test the error in a language-independent way.
Description
error(…)
allows to issue an error. By default error
- stops the current execution,
- displays in the console the recursive calling tree leading to the error,
- displays the given error
message
, - and resumes to the prompt level.
In order to handle the error without stopping the execution, it is possible to catch
it by using try … catch
or execstr(…,'errcatch')
,
and to test it with lasterror(…)
.
error(message)
yields an error #10000 (and displays the given
message
).
error(message, n)
displays the character string contained in
message
. The numerical identifier ascribed to the error is
n
.
See error_table for a list of standard error messages. Most of them are already translated in the 4 main supported languages.
Examples
function test(a) if argn(2)~=1 msg = gettext("%s: Wrong number of input arguments: %d expected.\n") error(msprintf(msg, "test", 1)) end endfunction function myfun() a = 1; test() endfunction // ---------- error(['A multi line' 'error message']) error(500, 'Error: my error message') [m, n] = lasterror() test() myfun()
--> error(['A multi line' 'error message']) A multi line error message --> error(500, 'Error: my error message') Error: my error message --> [m, n] = lasterror() n = 500. m = Error: my error message --> test() at line 4 of function test test: Wrong number of input arguments: 1 expected. --> myfun() at line 4 of function test at line 3 of function myfun test: Wrong number of input arguments: 1 expected.
See also
- lasterror — get last recorded error message
- error_table — list of main standard errors messages
- gettext — indexes or/and translates some indexed english messages
- warning — warning messages
- try — beginning of try block in try-catch control instruction
- execstr — execute Scilab code in strings
- where — get current instruction calling tree
History
Version | Description |
5.0.0 | error(n, message) syntax introduced. |
5.4.0 | The error function can take vector of strings as input argument. |
6.0.0 | The error(n) and error(n, pos) syntaxes
are no longer supported: Providing an explicit error message is now mandatory.
There is no longer any absolute error identifier. |
Report an issue | ||
<< errclear | Error handling | error_table >> |