Hi All,

Could you please clear my doubt why this second catch block is called when exception is thrown only once.

#include <iostream>
using namespace std;

class E {
    const char* error;
    E(const char* arg): error(arg) {}

class B {
    B() {};
    ~B(){cout<<"~B() called"<<endl;}

class D: public B {
    ~D() { cout<<"~D() called"<<endl; }

D::D() try :B(){
    throw E("Exception in D");
} catch(E&e)

int main()
    try {
        D val;
    }catch(...) { cout<<"Last"<<endl;}

Paragraph 15.3.15 of the standard: "The currently handled exception is rethrown if control reaches the end of a handler of the function-try-block of a constructor or destructor."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.