Created
January 18, 2012 16:56
-
-
Save sinannar/1634027 to your computer and use it in GitHub Desktop.
catch(...) block learning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Exception | |
{ | |
public: | |
Exception(string e) | |
{ | |
situation=e; | |
} | |
string getProblem() const | |
{ | |
return situation; | |
} | |
private: | |
string situation; | |
}; | |
void funA(); | |
void funB(); | |
void funC(); | |
void funD(); | |
int main() | |
{ | |
try{ | |
cout<<"calling A"<<endl; | |
funA(); | |
cout<<"back from A"<<endl; | |
} | |
catch(...){///look here carefully | |
} | |
cout<<"catched it"<<endl; | |
return 0; | |
} | |
void funA() | |
{ | |
cout<<"calling B"<<endl; | |
funB(); | |
cout<<"back from B"<<endl; | |
} | |
void funB() | |
{ | |
cout<<"calling C"<<endl; | |
funC(); | |
cout<<"back from C"<<endl; | |
} | |
void funC() | |
{ | |
cout<<"calling D"<<endl; | |
funD(); | |
cout<<"back from D"<<endl; | |
} | |
void funD() | |
{ | |
if(true) | |
throw Exception("excp from D"); | |
cout<<"Here i am on D"<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment