Yes, it will be very common. Usually, for example, catch std::exception , although the exception std::bad_alloc is likely to be a derived exception of the type std::bad_alloc or std::runtime_error .
You can catch the base type and the derived one, and they will be caught in turn, but you must first catch the derived type.
try { // code which throws bad_alloc } catch ( const std::bad_alloc & e ) { // handle bad_alloc } catch ( const std::exception & e ) { // catch all types of std::exception, we won't go here // for a bad_alloc because that been handled. } catch ( ... ) { // catch unexpected exceptions throw; }
source share