How to handle derived class and base class exceptions in C++?

A catch statement for a base class will also catch exceptions for a derived class (if it exists). So, to avoid confusion a derived class is put first in the catch sequence.

For Example:

#include <iostream>

using namespace std;

class base_class {


class derived_class: public base_class {


int main()


derived_class derived;

try {

throw derived;


catch(derived_class d) {


catch(base_class b) {


return 0;


Leave a Reply