Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - English

Change language to:
Français - 日本語 - Português - Русский

Please note that the recommended version of Scilab is 2023.1.0. This page might be outdated.
See the recommended documentation of this function

Scilab Help >> Scilab > Error handling > error


reports a run time error


error(message, n)
error(n, 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.


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.


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.


function test(a)
    if argn(2)~=1
        msg = gettext("%s: Wrong number of input arguments: %d expected.\n")
        error(msprintf(msg, "test", 1))
function myfun()
    a = 1;

// ----------

error(['A multi line' 'error message'])
error(500, 'Error: my error message')
[m, n] = lasterror()

--> 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  =
 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


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 >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:49:18 CET 2020