help-octave
[Top][All Lists]
Advanced

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

Re: try catch end


From: John W. Eaton
Subject: Re: try catch end
Date: Mon, 9 May 2005 15:04:01 -0400

On  9-May-2005, Tom Holroyd wrote:

| OK, the problem is the absence of the catch.
| 
| try, a = a; end;
| 
| is a parse error, but,
| 
| try, a = a; catch disp('moo'); end;
| 
| is fine.
| 
| In matlab, the catch is optional.

Please try the following patch.  It's relative to the current 2.1.x
branch of the CVS archive, but will probably apply to other recent
versions.

In the future, please report bugs to the address@hidden list.  If
you're not sure what to include in your report so that someone can fix
the problem, please read http://www.octave.org/bugs.html before
sending your report.

Thanks,

jwe


src/ChangeLog:

2005-05-09  John W. Eaton  <address@hidden>

        * parse.y (except_command):
        Make catch clause optional in try statements.
        * pt-except.cc (tree_try_catch_command::eval):
        Always buffer error messages.


Index: src/parse.y
===================================================================
RCS file: /usr/local/cvsroot/octave/src/parse.y,v
retrieving revision 1.224.2.11
diff -u -r1.224.2.11 parse.y
--- src/parse.y 27 Apr 2005 20:22:18 -0000      1.224.2.11
+++ src/parse.y 9 May 2005 19:02:18 -0000
@@ -1156,6 +1156,11 @@
                    if (! ($$ = make_try_command ($1, $4, $8, $9, $2, $6)))
                      ABORT_PARSE;
                  }
+               | TRY stash_comment opt_sep opt_list END
+                 {
+                   if (! ($$ = make_try_command ($1, $4, 0, $5, $2, 0)))
+                     ABORT_PARSE;
+                 }
                ;
 
 // ===========================================
Index: src/pt-except.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/pt-except.cc,v
retrieving revision 1.19.2.1
diff -u -r1.19.2.1 pt-except.cc
--- src/pt-except.cc    26 Apr 2005 19:43:59 -0000      1.19.2.1
+++ src/pt-except.cc    9 May 2005 19:02:18 -0000
@@ -99,11 +99,8 @@
   
   MAYBE_DO_BREAKPOINT;
 
-  if (catch_code)
-    {
-      unwind_protect_int (buffer_error_messages);
-      buffer_error_messages++;
-    }
+  unwind_protect_int (buffer_error_messages);
+  buffer_error_messages++;
 
   unwind_protect::add (do_catch_code, catch_code);
 
@@ -126,8 +123,7 @@
       unwind_protect::discard ();
 
       // For restoring buffer_error_messages.
-      if (catch_code)
-       unwind_protect::run ();
+      unwind_protect::run ();
 
       // Also clear the frame marker.
       unwind_protect::discard ();



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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