|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-07-04 13:33:27
Dean Michael Berris wrote:
> On 7/4/06, Emil Dotchevski <emildotchevski_at_[hidden]> wrote:
>>
>> I don't think it can be completely avoided. If you throw
>> failed<foo>, you should catch(foo &) to handle the exception. At
>> this point you do need a dynamic_cast to get to the exception_info
>> sub-object. You could have a virtual function in foo to get you an
>> exception_info *, but I don't think that this is appropriate.
>>
>
> Let's see:
>
> template <typename _T>
> class failed : public exception_info, public std::exception {
> public:
> failed() { };
> explicit failed (const _T & e) : _wrapped_exception(e) { };
>
> // ... other common methods ...
> };
>
> //...
> try {
> ...
> } catch (exception_info & e) {
> ...
> }
But the whole point is that in some scenarios you want to catch T, not
exception_info. You are interested in a read_error and have an appropriate
response to it ready, but the rest of the exceptions must be propagated
unharmed.
So you catch( read_error const & r ) and use dynamic_cast to see whether it
also contains exception_info.
Obviously, if you want to catch all exceptions regardless of type, there is
no need for a dynamic_cast. You catch exception_info, std::exception, and
... (in that order.)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk