The reasons for the structure of the standard exception hierarchy

This is a picky thing, and probably just my OCD, but I was wondering why the standard hierarchy of exception classes is set up as it is.

exception bad_alloc bad_cast bad_typeid bad_exception ios_base::failure runtime_error subclasses... logic_error subclasses... 

Could all bad_ * exceptions be subclasses like lang_support_error? And ios_base :: failure seems completely out of place.

Are there any historical or technical reasons why the hieratic turned out to be so?

+6
source share
1 answer

If I remember correctly, the logic was:

  • logic_error will be the equivalent of assert , but with less harsh behavior
  • runtime_error will be the foundation of everyone else

However, as you noticed, it does not quite execute even in the most standard library.

The main issue that I think of is subjectivity: std::out_of_range a logic_error or runtime_error ?

This is subjective ...

+3
source

Source: https://habr.com/ru/post/888240/


All Articles