Skip to content

Instantly share code, notes, and snippets.

@fredemmott
Last active August 9, 2018 02:22
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 fredemmott/e3b7f6f1b41be02e5980416677dd05a6 to your computer and use it in GitHub Desktop.
Save fredemmott/e3b7f6f1b41be02e5980416677dd05a6 to your computer and use it in GitHub Desktop.
try-catch
fredemmott-pro:tmp fredemmott$ cat test.cpp
#include <iostream>
using namespace std;
class Foo {};
inline __attribute__((__always_inline__)) void do_stuff() {
// This is a local label everywhere except MacOS; on MacOS,
// as it's a non-local label, a noexcept frame gets generated,
// then inlined. The noexcept frame probably shouldn't be generated,
// but hey.
//
// This can be fixed by using `Lfoo` on MacOS, but should remain
// '.Lfoo' pretty much everywhere else
__asm__ __volatile__ (".Lfoo:\n");
cout << "Hello, world" << endl;
}
int main(int argc, char** argv, char** envv) {
try {
cout << "In try" << endl;
do_stuff();
throw Foo();
} catch (Foo f) {
cout << "in catch Foo" << endl;
} catch (...) {
cout << "in catch ..." << endl;
}
cout << "at end of function" << endl;
}
fredemmott-pro:tmp fredemmott$ g++ test.cpp
fredemmott-pro:tmp fredemmott$ ./a.out
In try
Hello, world
libc++abi.dylib: terminating with uncaught exception of type Foo
Abort trap: 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment