FAQ: Difference between revisions
→Octave extensions: "can not" presumably intended as "cannot"
AndrewJanke (talk | contribs) m (fix typo) |
(→Octave extensions: "can not" presumably intended as "cannot") |
||
Line 729: | Line 729: | ||
Octave has a lisp-like {{Codeline|unwind_protect}} block that allows blocks of code that terminate in an error to ensure that the variables that are touched are restored. You can do something similar with try/catch combined with {{Codeline|rethrow (lasterror ())}} in Matlab, however rethrow and lasterror are only available in Octave 2.9.10 and later. MATLAB 2008a also introduced {{Codeline|OnCleanUp}} that is similar to {{Codeline|unwind_protect}}, except that the object created by this function has to be explicitly cleared in order for the cleanup code to run. | Octave has a lisp-like {{Codeline|unwind_protect}} block that allows blocks of code that terminate in an error to ensure that the variables that are touched are restored. You can do something similar with try/catch combined with {{Codeline|rethrow (lasterror ())}} in Matlab, however rethrow and lasterror are only available in Octave 2.9.10 and later. MATLAB 2008a also introduced {{Codeline|OnCleanUp}} that is similar to {{Codeline|unwind_protect}}, except that the object created by this function has to be explicitly cleared in order for the cleanup code to run. | ||
Note that using try/catch combined with {{Codeline|rethrow (lasterror ())}} | Note that using try/catch combined with {{Codeline|rethrow (lasterror ())}} cannot guarantee that global variables will be correctly reset, as it won't catch user interrupts with Ctrl-C. For example | ||
<syntaxhighlight lang="Matlab"> | <syntaxhighlight lang="Matlab"> |