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,
nallows 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 |
|
| 5.4.0 | The |
| 6.0.0 | The |
| Report an issue | ||
| << errclear | Error handling | error_table >> |