diff libinterp/parse-tree/pt-eval.cc @ 17249:923ce8b42db2

improve try-catch-statement to save exception to a variable (bug #33217) * oct-parse.in.yy (except_command): Handle exception identifiers. * oct-parse.in.yy, parse.h (octave_base_parser::make_try_command): New arg, ID. * pt-except.cc, pt-except.h (tree_try_catch_command::expr_id): New data member. (tree_command::tree_command): Initialize it. (tree_command::~tree_command): Delete it. (tree_command::identifier): New function. * pt-check.cc (tree_checker::visit_try_catch_command): Check for valid expr_id. * pt-pr-code.cc (tree_print_code::visit_try_catch_command): Print expr_id. * pt-eval.cc (tree_evaluator::visit_try_catch_command): Assign message and identifier to variable. * try.tst: New test. * NEWS: Note change.
author Stefan Mahr <dac922@gmx.de>
date Tue, 13 Aug 2013 19:35:53 +0200
parents 302157614308
children bc924baa2c4e
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc	Tue Aug 13 19:31:59 2013 -0400
+++ b/libinterp/parse-tree/pt-eval.cc	Tue Aug 13 19:35:53 2013 +0200
@@ -921,6 +921,27 @@
 
           buffer_error_messages--;
 
+          tree_identifier *expr_id = cmd.identifier ();
+          octave_lvalue ult;
+
+          if (expr_id)
+            {
+
+              octave_scalar_map err;
+
+              ult = expr_id->lvalue ();
+
+              if (error_state)
+                return;
+
+              err.assign ("message", last_error_message ());
+              err.assign ("identifier", last_error_id ());
+
+              if (! error_state)
+                ult.assign (octave_value::op_asn_eq, err);
+
+            }
+
           if (catch_code)
             catch_code->accept (*this);
         }