octave-maintainers
[Top][All Lists]
Advanced

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

Re: Using exceptions in the core


From: Olaf Till
Subject: Re: Using exceptions in the core
Date: Sun, 27 Sep 2015 10:38:15 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

On Sat, Sep 26, 2015 at 12:13:03PM -0400, John W. Eaton wrote:
> ...
> But in other cases, more changes are needed, or we have to accept different
> behavior.  For example we currently have things like this
> 
>   std::string val = args(0).string_value ();
> 
>   if (! error_state)
>     {
>       // normal processing...
>     }
>   else
>     error ("foobar: first argument must be a character string");
> 
> With the change to have the error function throw an exception, the
> octave_value::string_value extractor will throw an error and so the
> subsequent more useful message will not appear.  I think in these cases, the
> fix is to write
> 
>   if (! args(0).is_string ())
>     error ("foobar: first argument must be a character string");
> 
>   // normal processing
> 
> But there are other cases of extracting values that are not as clear and may
> need more work.

What about providing

#define SOME_MACRO(code, informative_error_message) \
...

which executes 'code' within try{} and prints
'informative_error_message' and rethrows the exception within catch{}?

Your example would turn to:

SOME_MACRO(std::string val = args(0).string_value (), "foobar: first argument 
must be a character string")

// normal processing

Olaf

-- 
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net

Attachment: signature.asc
Description: Digital signature


reply via email to

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