octave-maintainers
[Top][All Lists]
Advanced

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

Re: unwind_protect & try/catch combined corner case


From: Jaroslav Hajek
Subject: Re: unwind_protect & try/catch combined corner case
Date: Thu, 7 Jan 2010 14:28:16 +0100

On Thu, Jan 7, 2010 at 2:08 PM, Søren Hauberg <address@hidden> wrote:
> tor, 07 01 2010 kl. 13:36 +0100, skrev Jaroslav Hajek:
>> Maybe the whole matter is just too much
>> of a corner case for anyone to really care.
>
> It really does sound like an obscure corner case. But how about this
> semi-real-world example?
>
>        function main ()
>          try
>            do_stuff_in_dir ("some/directory");
>          catch
>            warning ("An error occurred, but I don't care");
>          end_try_catch
>        endfunction
>
>        function do_stuff_in_dir (directory)
>          unwind_protect
>            wd = pwd ();
>            cd (directory);
>            do_stuff ();
>          unwind_protect_cleanup
>            # this will raise an error because I forgot the parenthesis
>            cd wd
>          end_unwind_protect
>        endfunction
>
> In this case, I will not get an error, right? I think it would be really
> helpful if I got the error message from 'cd'.

Yes, if you press Ctrl-C while do_stuff is doing stuff, then it will
silently bring you to the prompt. But of course you will discover the
problem if you won't interrupt the function.

> So, I think it might be
> good if errors raised during interrupt handling could not get caught.
>

Not that generally, I suppose. You surely want to be able to catch an
error inside the cleanup block.
But I understand what you mean. What about the following patch?

diff --git a/src/pt-eval.cc b/src/pt-eval.cc
--- a/src/pt-eval.cc
+++ b/src/pt-eval.cc
@@ -949,6 +949,10 @@
         }
       catch (...)
         {
+          // Prevent errors being silently ignored by external handlers.
+          unwind_protect frame;
+          frame.protect_var (buffer_error_messages);
+          buffer_error_messages = 0;
           // Run the cleanup code on exceptions, so that it is run even in case
           // of interrupt or out-of-memory.
           do_unwind_protect_cleanup_code (cleanup_code);

this gives:

octave:1> main
^Cerror: wd: No such file or directory

but I'm not sure this is right.

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

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