Date: Tue, 27 Dec 2022 11:15:32 +0000
On Tue, 27 Dec 2022, 11:07 Frederick Virchanza Gotham via Std-Proposals, <
std-proposals_at_[hidden]> wrote:
>
> Imagine if we could do this:
>
> try
> {
> // some code here
> }
> template<typename T> catch(T &obj)
> {
> if constexpr ( requires { obj.what(); } )
> {
> cout << obj.what() << endl;
> }
> else
> {
> cout << "Thrown object is a " << typeid(T).name() << " and its
> value is " << obj << endl;
> }
> }
>
> Basically it would be the same as having 'catch(...)' except that we
> haven't lost the type info.
>
That's obviously impossible; what happens if an exception is thrown and
caught in two TUs, or worse DSOs, that were compiled causally disconnected?
The RTTI part might be feasible; it certainly is on Itanium, I've forgotten
whether it is on Windows. Perhaps there's a proposal to add type info to
std::exception_ptr?
std-proposals_at_[hidden]> wrote:
>
> Imagine if we could do this:
>
> try
> {
> // some code here
> }
> template<typename T> catch(T &obj)
> {
> if constexpr ( requires { obj.what(); } )
> {
> cout << obj.what() << endl;
> }
> else
> {
> cout << "Thrown object is a " << typeid(T).name() << " and its
> value is " << obj << endl;
> }
> }
>
> Basically it would be the same as having 'catch(...)' except that we
> haven't lost the type info.
>
That's obviously impossible; what happens if an exception is thrown and
caught in two TUs, or worse DSOs, that were compiled causally disconnected?
The RTTI part might be feasible; it certainly is on Itanium, I've forgotten
whether it is on Windows. Perhaps there's a proposal to add type info to
std::exception_ptr?
Received on 2022-12-27 11:15:46