Skip to content

Instantly share code, notes, and snippets.

@odeblic
Last active July 27, 2017 11:26
Show Gist options
  • Save odeblic/0ee40b2a3ae3a8151955198e8d217e0d to your computer and use it in GitHub Desktop.
Save odeblic/0ee40b2a3ae3a8151955198e8d217e0d to your computer and use it in GitHub Desktop.
Exception handling, enabled or not
#include <iostream>
#include <exception>
#include <cstdlib>
void f() noexcept(false)
{
std::cout << "f()" << std::endl;
throw('F');
}
void g() noexcept(false)
{
std::cout << "g()" << std::endl;
throw('G');
try
{
throw('G');
}
catch(char)
{
std::cout << "g::g()" << std::endl;
}
}
void h()
{
std::cout << "h()" << std::endl;
throw('H');
}
void myterminate()
{
std::cout << "myterminate()" << std::endl;
abort();
}
int main(int argc, char * argv[])
{
std::set_terminate(myterminate);
g();
try
{
g();
}
catch(char e)
{
std::cout << "exception of type 'char': " << e << std::endl;
}
catch(...)
{
std::cout << "exception of unknown type" << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment