changeset 21922:c34f9c182dcf

Make debug_on_error to apply to the "catch" block of try/catch (bug #47685) * pt-eval.cc (tree_evaluator::visit_try_catch_command): Unwind Vdebug_on_error etc. before executing catch_code.
author Rik <rik@octave.org>
date Thu, 16 Jun 2016 08:23:30 -0700
parents ecfcc8527661
children 43a5d019e6cc
files libinterp/parse-tree/pt-eval.cc
diffstat 1 files changed, 37 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc	Thu Jun 16 01:00:20 2016 -0400
+++ b/libinterp/parse-tree/pt-eval.cc	Thu Jun 16 08:23:30 2016 -0700
@@ -830,51 +830,50 @@
 void
 tree_evaluator::visit_try_catch_command (tree_try_catch_command& cmd)
 {
-  octave::unwind_protect frame;
-
-  frame.protect_var (buffer_error_messages);
-  frame.protect_var (Vdebug_on_error);
-  frame.protect_var (Vdebug_on_warning);
-
-  buffer_error_messages++;
-  Vdebug_on_error = false;
-  Vdebug_on_warning = false;
-
-  tree_statement_list *catch_code = cmd.cleanup ();
-
-  // The catch code is *not* added to unwind_protect stack; it doesn't need
-  // to be run on interrupts.
-
-  tree_statement_list *try_code = cmd.body ();
-
   bool execution_error = false;
 
-  if (try_code)
-    {
-      try
-        {
-          in_try_catch++;
-          try_code->accept (*this);
-          in_try_catch--;
-        }
-      catch (const octave_execution_exception&)
-        {
-          recover_from_exception ();
+  { // unwind frame before catch block
+    octave::unwind_protect frame;
+
+    frame.protect_var (buffer_error_messages);
+    frame.protect_var (Vdebug_on_error);
+    frame.protect_var (Vdebug_on_warning);
+
+    buffer_error_messages++;
+    Vdebug_on_error = false;
+    Vdebug_on_warning = false;
+
+    // The catch code is *not* added to unwind_protect stack;
+    // it doesn't need to be run on interrupts.
+
+    tree_statement_list *try_code = cmd.body ();
 
-          in_try_catch--;          // must be restored before "catch" block
-          execution_error = true;
-        }
-    }
+    if (try_code)
+      {
+        try
+          {
+            in_try_catch++;
+            try_code->accept (*this);
+            in_try_catch--;
+          }
+        catch (const octave_execution_exception&)
+          {
+            recover_from_exception ();
+
+            in_try_catch--;          // must be restored before "catch" block
+            execution_error = true;
+          }
+      }
+  // Unwind to let the user print any messages from
+  // errors that occurred in the body of the try_catch statement,
+  // or throw further errors.
+  }
 
   if (execution_error)
     {
+      tree_statement_list *catch_code = cmd.cleanup ();
       if (catch_code)
         {
-          // Set up for letting the user print any messages from errors that
-          // occurred in the body of the try_catch statement.
-
-          buffer_error_messages--;
-
           tree_identifier *expr_id = cmd.identifier ();
           octave_lvalue ult;
 
@@ -889,10 +888,9 @@
               err.assign ("stack", last_error_stack ());
 
               ult.assign (octave_value::op_asn_eq, err);
-
             }
 
-              // perform actual "catch" block
+          // perform actual "catch" block
           if (catch_code)
             catch_code->accept (*this);
         }