Exceptions
Closed this issue · 5 comments
Currently std::runtime_exception
is thrown in a few cases. Should we have our own exception type?.
In the case of get<wrong_type>()
P0088R0 uses bad_variant_access
derived from logic_error
for this.
👍 to custom exception type if you see a benefit (as long as it inherits from std::exception
of course).
A custom exception type would allow a user to differentiate between an exception thrown by our variant type and an exception that is somehow propagated from a type wrapped in the variant. I am not sure this is strictly necessary, but it would be cleaner in any case.
Before I change this: Is there any code checking for this exception somewhere? @artemp ?
@joto - sounds good re: custom exception.
Lets derive it from std::exception
so existing code will continue to work or at least it'll be easy to fix.
I have create a new class bad_variant_access
now derived from std::runtime_error
and use this in the get<T>()
functions. This is backwards-compatible. User code using this should switch to the new type and then we can later on switch the parent class to the more correct std::logic_error
as in the upcoming standard.