Created
January 18, 2012 16:54
-
-
Save sinannar/1634015 to your computer and use it in GitHub Desktop.
Throw exception from where
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> | |
//#define EXCEPTION_TEST1 | |
#define EXCEPTION_TEST2 | |
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(Exception e){ | |
cout<<e.getProblem()<<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() | |
{ | |
#ifdef EXCEPTION_TEST1 | |
if(true) | |
throw Exception("excp from D"); | |
cout<<"Here i am on D"<<endl; | |
#endif | |
#ifdef EXCEPTION_TEST2 | |
if(false) | |
throw Exception("excp from D"); | |
cout<<"Here i am on D"<<endl; | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment