Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoklavat committed Feb 2, 2021
1 parent 8d203f6 commit 2f27c91
Show file tree
Hide file tree
Showing 2 changed files with 290 additions and 103 deletions.
41 changes: 41 additions & 0 deletions 50-PolymorphicException.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//50-PolymorphicException

#include <iostream>

class A{
public:
virtual void raise();
};

void A::raise(){
std::cout << "Class A raised exception." << std::endl;
throw *this;
}

class B: public A{
public:
virtual void raise();
};

void B::raise(){
std::cout << "Class B raised exception." << std::endl;
throw *this;
}

void f(A& e){
e.raise();
}

int main(){
B b;

try{
f(b);
}
catch(B& e){
std::cout << "B type exception is catched." << std::endl;
}
catch(...){
std::cout << "Other type exception is catched." << std::endl;
}
}
Loading

0 comments on commit 2f27c91

Please sign in to comment.