[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #40828] Exception handling: MException object
From: |
John W. Eaton |
Subject: |
[Octave-bug-tracker] [bug #40828] Exception handling: MException object functions |
Date: |
Wed, 29 Dec 2021 14:14:59 -0500 (EST) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0 |
Follow-up Comment #12, bug #40828 (project octave):
@Guillaume: Yes, I forgot to include the small change I made to your
MException.m:
This part changes it to set hasBeenCaught to true if the constructor is called
with 2 arguments. Maybe I should have used the value of the second argument,
but I just needed to set hasBeenCaught to true.
--- MException.m 2021-12-28 09:18:56.304544115 -0500
+++ MException.m 2021-12-28 09:57:26.453914848 -0500
@@ -47,11 +47,16 @@
methods (Access = public)
function this = MException (id, template, varargin)
- if (nargin == 1 && isstruct (id))
- # Matlab does not have this constructor. Used internally by last().
+ if ((nargin == 1 || nargin == 2) && isstruct (id))
+ # Matlab does not have this constructor. Used internally by
+ # last() and by the evaluator in constructing exception
+ # objects in CATCH blocks.
this.identifier = id.identifier;
this.message = id.message;
this.stack = id.stack;
+ if (nargin == 2)
+ this.hasBeenCaught = true;
+ endif
else
if (nargin < 2 || nargout > 1)
print_usage ();
I also needed this change to accept Octave's error identifiers that include
'-' characters:
--- MException.m 2021-12-28 09:18:56.304544115 -0500
+++ MException.m 2021-12-28 09:57:26.453914848 -0500
@@ -65,7 +70,10 @@
if (! ischar (this.message) || (! isempty (this.message) && ! isrow
(this.message)))
error ("MException: Message must be a row string.");
endif
- if (! isempty(this.identifier) && isempty
(regexp(this.identifier,'^([a-zA-Z]\w*)(:[a-zA-Z]\w*)+$')))
+ if (! isempty (this.identifier)
+ && isempty (regexp (this.identifier,
+
+
"^([A-Za-z][A-Za-z)-9_-]*)(:[A-Za-z][A-Za-z0-9_-]*)*$")))
error ("MException: Invalid identifier.");
endif
endfunction
When we get this working it would probably be best to find a way to construct
the MException object without needing to evaluate a function so that Octave
will always correctly construct these objects even if the MException function
is shadowed by some user-defined function. I mean, I assume that Matlab
doesn't call a user-defined MException constructor if it happens to appear
somewhere in the the path, right?
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?40828>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/