|
From: | John W. Eaton |
Subject: | Re: Using exceptions in the core |
Date: | Tue, 06 Oct 2015 15:13:17 -0400 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 |
On 10/02/2015 06:14 PM, John W. Eaton wrote:
On 10/02/2015 03:15 PM, John W. Eaton wrote:On 10/02/2015 02:39 PM, Rik wrote:I also like the overloaded _value() method idea. We could start out small by just overloading the string_value () method since this seems to be one of the most frequent occurrences where the function expected a string, for an option maybe, but numeric input was given.Yes, I think this is the most frequent case of something like if (! args(0).is_string ()) { error ("..."); return retval; } so I think it makes sense to start with this one and see what we think. I'll work on this with my other changes.My current idea is attached. With it, you can write something like std::string url = args(0).string_value ("urlwrite: URL must be a string"); Comments?
Any comments on this proposal?I've now taken an initial pass through all of the Octave sources and have removed many simple uses of error_state. I primarily went after things like
if (error_state) return retval; if (! error_state) { ... } // No else or side effect.We are now left with about 490 more uses (down from over 1600, I think). Many of the remaining are of the form
std::string = args(0).string_value (); // Or some other value extraction. if (error_state) { error ("more specific error message"); return retval; }These will mostly be easy to remove but we should probably agree on exactly how we would prefer to handle the error. I suppose either overloading the various value extractors or writing some simple wrapper functions. Either way, the goal is really the same, to encapsulate the use of try/catch in a few places instead of sprinkling them all over the code.
jwe
[Prev in Thread] | Current Thread | [Next in Thread] |