Boost logo

Boost Users :

Subject: Re: [Boost-users] exception: use of error_info can mask real exceptions
From: Andrew Venikov (andrew.venikov_at_[hidden])
Date: 2009-05-25 02:02:34


Emil Dotchevski wrote:
> On Sun, May 24, 2009 at 10:09 PM, Andrew Venikov
> <andrew.venikov_at_[hidden]> wrote:
>> Emil Dotchevski wrote:
>>
>> <...>
>>> That's my point, you want some exceptions emitted by the throw
>>> expression to be ignored, and some not. <..>
>> I would rather say that the main exception should be thrown no matter
>> what.
>
> If you write:
>
> throw foo() << info1(bar());
>
> and bar() throws something (note, this function might have nothing to
> do with Boost Exception or foo), do you want that exception silently
> ignored?
By the same token I could ask: do you want foo() silently ignored?

>
>> When I write this:
>>
>> throw WidgetAllocError();
>>
>> It's pretty obvious what I want.
>> Of course, it would be nice to have more informative description, that's
>> why I would normally add:
>>
>> throw WidgetAllocError() << WidgetErrorDescription(strWidgetName);
>>
>> But this now changes the original intent. By the time we reach the throw
>> statement, we've made a decision that an error condition has been
>> reached and we want to indicate that error. If we continue propagating
>> WidgetAllocError(), then we'll at least know what kind of error
>> happened, albeit without extra information.
>
> That "albeit" is very important. It effectively requires the catch
> site to be able to deal with a WidgetAllocError that has no additional
> information in it. Are you sure you want to impose this requirement on
> all programs wrt all exceptions?
Agreed.
But if I understand correctly, even now the good style to catch
error_info is first to call get_error_info(), and then check the pointer
for null. "Imposing this requirement" here simply means doing that check
  for pointer not being equal to null. Or am I missing something? Are you
saying there is a way where we can assume that the returned pointer will
never be null?

It looks like we really have to decide, what's more important -
preserving the original exception or preserving a newer exception.
I'm trying to understand whether this dilemma simply presents a matter
of taste, or is there a real (if a little academical) problem to solve.
If I'm convinced that it's just a matter of taste - then I'm fine with
either way. But so far I feel that importance of receiving the original
exception outweighs the possible loss of other exceptions (which by the
way wouldn't be thrown in a first place if it wasn't for the original
exception)

Maybe others can chime in.

Thanks,
    Andy.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net