Friday, June 15, 2012

exception rethrow

#include <iostream>


struct A{
};


struct B:public A{
};



void handle(A& a){
  throw;
}


void f(){

  try{
    throw B();
  }catch(A& a){
    handle(a);
  }
}


int main(){
  try{
    f();
  }catch(B& b){
    std::cout<<"got a B"<<std::endl;
  }catch (A& a){
    std::cout<<"got an A"<<std::endl;
  }   
}


====output====

got a B

No comments:

Post a Comment