octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: try/finally


From: Andrew Janke
Subject: Re: try/finally
Date: Thu, 21 Mar 2019 01:15:45 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.5.3



On 3/21/19 1:01 AM, Mike Miller wrote:
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.


That makes sense. I hadn't thought of doing an explicit clear on the cleanup variable prior to function return. Thanks.

Andrew



reply via email to

[Prev in Thread] Current Thread [Next in Thread]