On Wed, Mar 20, 2019 at 22:42:40 -0400, Andrew Janke wrote:
On 3/20/19 10:32 PM, John W. Eaton wrote:
On 3/20/19 5:39 PM, Andrew Janke wrote:
Matlab has neither try/catch nor unwind_protect, so compatibility is
not an immediate concern. And I think they're more likely to add a
finally than an unwind_protect.
Matlab does have try/catch:
https://www.mathworks.com/help/matlab/ref/try.html
Sorry, I meant "Matlab doesn't have try/finally".
I know it's kind of like reading backwards, but using onCleanup might be
a simpler solution than nesting a try-catch inside of an unwind_protect:
finally = onCleanup (@() … clean up or restore something … );
try
## main code
catch
## handle errors
end_try_catch
clear finally ## force immediate execution? or just return
Doesn't work that well if your finally needs access to local variables
that may be changing inside the try block, but may be useful.