C++ Logo

std-proposals

Advanced search

[std-proposals] template<class T> catch (T &obj)

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 27 Dec 2022 11:07:27 +0000
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.

Received on 2022-12-27 11:07:29