Skip to content

Instantly share code, notes, and snippets.

@davidglezz
Created November 4, 2013 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidglezz/7310134 to your computer and use it in GitHub Desktop.
Save davidglezz/7310134 to your computer and use it in GitHub Desktop.
Simple c++ ErrorHandler with exceptions example.
#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