1
1
<?xml version="1.0" encoding="UTF-8"?>
2
2
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="try" xml:lang="en">
5
<refpurpose>beginning of try block in try-catch control
9
<refnamediv xml:id="catch">
10
<refname>catch</refname>
11
<refpurpose>beginning of catch block in try-catch control
16
<title>Calling Sequence</title>
26
<title>Description</title>
28
The <literal>try</literal>-<literal>catch</literal> control
29
instruction can be used to manage codes that could possibly generate
33
When a <literal>try</literal>-<literal>catch</literal> control
34
instruction is executed, normally only the statements between the
35
<literal>try</literal> and <literal>catch</literal> keywords are executed.
36
However, if an error occurs during execution of any of these statements,
37
the error is recorded, the remaining statements up to the
38
<literal>catch</literal> keyword are skipped and the statements between
39
the <literal>catch</literal> and <literal>end</literal> keywords are
40
executed using the default error handling mode (see <link linkend="errcatch">errcatch</link>).
43
The recorded error can be retrieved using the <link linkend="lasterror">lasterror</link> function.
46
The <literal>catch</literal> statements as well as the
47
<literal>catch</literal> keyword can be omitted if no alternative
51
Note that one can also use the <link linkend="execstr">execstr</link> function with
52
<literal>'errcatch'</literal> argument for error handling. This can be
53
particularly useful for handling syntactical errors.
56
Note also that <literal>try-catch</literal> is more or less similar
59
<programlisting role=""><![CDATA[
5
<refpurpose>beginning of try block in try-catch control
9
<refnamediv xml:id="catch">
10
<refname>catch</refname>
11
<refpurpose>beginning of catch block in try-catch control
16
<title>Calling Sequence</title>
26
<title>Description</title>
28
The <literal>try</literal>-<literal>catch</literal> control
29
instruction can be used to manage codes that could possibly generate
33
When a <literal>try</literal>-<literal>catch</literal> control
34
instruction is executed, normally only the statements between the
35
<literal>try</literal> and <literal>catch</literal> keywords are executed.
36
However, if an error occurs during execution of any of these statements,
37
the error is recorded, the remaining statements up to the
38
<literal>catch</literal> keyword are skipped and the statements between
39
the <literal>catch</literal> and <literal>end</literal> keywords are
40
executed using the default error handling mode (see <link linkend="errcatch">errcatch</link>).
43
The recorded error can be retrieved using the <link linkend="lasterror">lasterror</link> function.
46
The <literal>catch</literal> statements as well as the
47
<literal>catch</literal> keyword can be omitted if no alternative
51
Note that one can also use the <link linkend="execstr">execstr</link> function with
52
<literal>'errcatch'</literal> argument for error handling. This can be
53
particularly useful for handling syntactical errors.
56
Note also that <literal>try-catch</literal> is more or less similar
59
<programlisting role=""><![CDATA[
60
60
if execstr("<try instructions>","errcatch")<>0 then
61
61
<catch instructions>
63
63
]]></programlisting>
65
It uses the same internal mechanism as <link linkend="errcatch">errcatch</link>. It is the reason why <link linkend="errcatch">errcatch</link> or
66
<emphasis>execstr(...,"errcatch")</emphasis> cannot be included in
67
<literal>try</literal>-<literal>catch</literal> control structures. This
68
context is detected and produces a specific error message (this error is
69
caught and stored like any other error if it is triggered in the
70
<literal>try</literal> block).
73
However, <literal>try</literal>-<literal>catch</literal> control
74
structures can be nested (see example 2 below).
78
<title>Examples</title>
79
<programlisting role="example"><![CDATA[
65
It uses the same internal mechanism as <link linkend="errcatch">errcatch</link>. It is the reason why <link linkend="errcatch">errcatch</link> or
66
<emphasis>execstr(...,"errcatch")</emphasis> cannot be included in
67
<literal>try</literal>-<literal>catch</literal> control structures. This
68
context is detected and produces a specific error message (this error is
69
caught and stored like any other error if it is triggered in the
70
<literal>try</literal> block).
73
However, <literal>try</literal>-<literal>catch</literal> control
74
structures can be nested (see example 2 below).
78
<title>Examples</title>
79
<programlisting role="example"><![CDATA[
81
81
file_path=TMPDIR+'/wrong'
113
113
nestedtry(1,"a string")
114
114
nestedtry("a string","a string")
115
115
]]></programlisting>
117
<refsection role="see also">
118
<title>See Also</title>
119
<simplelist type="inline">
121
<link linkend="error">error</link>
124
<link linkend="execstr">execstr</link>
127
<link linkend="if">if</link>
130
<link linkend="lasterror">lasterror</link>
133
<link linkend="errcatch">errcatch</link>
117
<refsection role="see also">
118
<title>See Also</title>
119
<simplelist type="inline">
121
<link linkend="error">error</link>
124
<link linkend="execstr">execstr</link>
127
<link linkend="if">if</link>
130
<link linkend="lasterror">lasterror</link>
133
<link linkend="errcatch">errcatch</link>