Search code examples
c++c++23

Catch std::bad_expected_access


std::bad_expected_access is a template class that is thrown. I have code that only cares that any instantiation of it is thrown, not which instantiation. Is there a way to catch (or some other mechanism) all instantiations of a template that are thrown?


Solution

  • All specializations of std::bad_expected_access inherit from std::bad_expected_access<void>.

    Catch std::bad_expected_access<void>