Created
November 4, 2013 22:16
-
-
Save davidglezz/7310134 to your computer and use it in GitHub Desktop.
Simple c++ ErrorHandler with exceptions example.
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> | |
#include <string> | |
using namespace std; | |
int main() | |
{ | |
int error = 0; | |
try | |
{ | |
cin >> error; | |
if (error == 1) | |
throw string("The error msg"); | |
if (error == 2) | |
throw 1234; | |
} | |
catch (string str) | |
{ | |
cout << "String Exception: " << str << '\n'; | |
} | |
catch (int n) | |
{ | |
cout << "Number Exception: " << n << '\n'; | |
} | |
// ... | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment