Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.1.0 - Русский


execstr

execute Scilab code in strings

Syntax

execstr(instr)
ierr = execstr(instr,'errcatch' [,msg])
[ierr, errormsg] = execstr(instr,'errcatch' [,msg])
[ierr, errormsg, callstack] = execstr(instr,'errcatch' [,msg])

Arguments

instr

a vector of character strings, Scilab instruction to be executed.

ierr

an integer, 0 or error number.

msg

a character string with values 'm' or 'n'. Default value is 'n'.

errormsg

error message in case of error and with 'errcatch' flag.

callstack

callstack in case of error and with 'errcatch' flag.

Description

Executes the Scilab instructions given in argument instr.

Note that instr should not make use of continuation marks (..)

If the 'errcatch' flag is not present, error handling works as usual.

If the 'errcatch' flag is set, and an error is encountered while executing the instructions defined in instr, execstr issues no error message, but aborts execution of the instr instructions (at the point where the error occurred), and resumes with ierr equal to the error number. In this case the display of the error message is controlled by the msg option:

"m"

error message is displayed and recorded.

"n"

no error message is displayed, but the error message is recorded (see lasterror). This is the default.

ierr = execstr(instr, 'errcatch') can handle syntactical errors. This is useful for evaluation of instruction obtained by a query to the user.

Examples

execstr('a=1') // sets a=1.
execstr('1+1') // does nothing (while evstr('1+1') returns 2)

execstr(['if %t then';
         '  a=1';
         '  b=a+1';
         'else'
         ' b=0'
         'end'])

execstr('a=zzzzzzz','errcatch')
execstr('a=zzzzzzz','errcatch','m')

//syntax errors
execstr('a=1?02','errcatch')
lasterror(%t)

execstr('a=[1 2 3)','errcatch')
lasterror(%t)

// variable1 does not exist
if execstr('variable1;','errcatch')<>0 then
   disp("Trigger an error");
else
   disp("execstr is happy");
end

// variable2 exists ... no error is triggered by execstr
variable2=[2,3];
if execstr('variable2;','errcatch')<>0 then
   disp("Trigger an error");
else
   disp("execstr is happy");
end

//get errormsg if case of error
[_ b] = execstr("acosd(""a"");", "errcatch")

See also

  • evstr — вычисление выражений
  • lasterror — получение последнего записанного сообщения об ошибке
  • error — сообщает об ошибке во время выполнения
  • try — начало блока try в управляющей структуре try-catch
Report an issue
<< exec Функции feval >>

Copyright (c) 2022-2024 (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:
Mon Jun 17 17:55:12 CEST 2024