This is a picky thing and it is probably just my OCD flairing up but I was wondering why the standard exception class hierarchy is set up as it is.
exception
bad_alloc
bad_cast
bad_typeid
bad_exception
ios_base::failure
runtime_error
subclasses...
logic_error
subclasses...
Couldn’t all the bad_* exceptions just be subclasses of something like lang_support_error? And ios_base::failure seems completely out of place.
Is there some historical or technical reasons the hierachy ended up like this?
If I remember correctly, the logic was:
logic_errorwould be the equivalent of anassert, but with less drastic behaviorruntime_errorwould be the base of all othersHowever, as you noticed, it does not quite hold, even in the standard library itself.
The main issue I guess is subjectivity: is
std::out_of_rangealogic_erroror aruntime_error?It’s subjective…