<?xml version="1.0" encoding="UTF-8"?>
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns3="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="lasterror" xml:lang="en">
    <refnamediv>
        <refname>lasterror</refname>
        <refpurpose>get last recorded error message</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>str=lasterror( [opt] )
            [str,n]=lasterror([opt])
            [str,n,line,func]=lasterror([opt])
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>str</term>
                <listitem>
                    <para>a vector of character strings or an empty matrix. The last
                        recorded error message.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>n</term>
                <listitem>
                    <para>an integer, 0 or the last recorded error number.</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>line</term>
                <listitem>
                    <para>an integer, 0 or the last recorded function line number.</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>func</term>
                <listitem>
                    <para>a string, the last recorded function name.</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>opt</term>
                <listitem>
                    <para>a boolean, if %t recorded message is cleared. Default is
                        %t.
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>Each time an error occurs, the Scilab error handler records it in an
            internal table (only the last one is retained). The
            <literal>lasterror</literal> function allows to get the message, the error
            number, the current function (if any) and the current line number in the
            current function out of this table.
        </para>
        <para>
            The reported line number is the <emphasis>physical</emphasis> line
            number where the last error occurred. Note that Scilab versions before 5.0
            used to report the <emphasis>logical</emphasis> line number of the last
            error. There is a difference only if the function in error includes
            <emphasis>continued lines</emphasis> (see <link linkend="dot">dot</link>)
            before the point where the error happened.
        </para>
        <para>
            This function is especially useful while using <link linkend="execstr">execstr</link>.
        </para>
        <para>The recorded error message may be retained for a further call to
            <literal>lasterror</literal> using
            <literal>lasterror(%f)</literal>.
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
ierr=execstr('a=zzzzzzz','errcatch')
if ierr>0 then
  disp(lasterror())
end
 ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="execstr">execstr</link>
            </member>
            <member>
                <link linkend="error">error</link>
            </member>
            <member>
                <link linkend="errclear">errclear</link>
            </member>
            <member>
                <link linkend="edit_error">edit_error</link>
            </member>
        </simplelist>
    </refsection>
</refentry>
