|
Boost : |
Subject: Re: [boost] Boost and exceptions
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2012-06-25 13:09:05
AMDG
On 06/25/2012 09:37 AM, Robert Ramey wrote:
> Emil Dotchevski wrote:
>> On Sun, Jun 24, 2012 at 11:33 PM, Robert Ramey <ramey_at_[hidden]> wrote:
>> <snipped code>
>>
>> First, as you point out, your code can't be deployed even if it was
>> correct, because many compilers don't yet implement
>> std::exception_ptr.
>
> There a couple of possible answers here, but the simplest would be
> just to say that you'd need to implement the standard functions for
> this compiler. I cursory look at the microsoft documentation suggests
> that this would be possible. and not all that difficult.
>
>> Secondly, your program erases the type of the exception object. In
>> C++, the type of the exception and not its value corresponds to its
>> semantics.
>
> hmmm looks to me that my program is not losing the type.
That's not what Emil said. "erases the type"
means that it hides everything behind a
single static type and forces you to dynamic
cast to find the real type.
I really don't want to read or write
code that looks like this, and I don't
think that the problem can be solved
without adding something to the original
throw site.
The problems become even worse when you
have more than one independent
implementation of this kind of handling,
which don't know about each other:
void handle_my_exception(my_exception&);
void handle_exception_wrapper1(exception_wrapper_base1& e) {
try {
std::rethrow_exception(e.me);
} catch(my_exception& me) {
handle_my_exception(me);
} catch(exception_wrapper_base2& e2) {
handle_exception_wrapper2(e2);
} catch(...) {
handle_unknown_exception();
}
}
void handle_exception_wrapper2(exception_wrapper_base2& e) {
try {
std::rethrow_exception(e.me);
} catch(my_exception& me) {
handle_my_exception(me);
} catch(exception_wrapper_base1& e1) {
handle_exception_wrapper1(e1);
} catch(...) {
handle_unknown_exception();
}
}
try {
// Lots of stuff
} catch(my_exception& e) {
handle_my_exception(e);
} catch(exception_wrapper_base1& e) {
handle_exception_wrapper1(e);
} catch(exception_wrapper_base2& e) {
handle_exception_wrapper2(e);
}
I don't even want to think about what
you need to do if you want to let
anything that isn't my_exception
go by unchanged.
I think that you've gotten so fixated
on avoiding instrumenting the original
throw site, that it's blinding to the
readability issues with your solutions.
> The highest
> level catch does catch the original type and just to be sure I used typeid
> to print the type restored at this level. So the program output is
>
> $ ./test_misc
> caught other exception # display original exception type
> caught exception_wrapper_base
> caught my_exception # display exception type at highest level
> 999 # display attached information.
>
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk