/* This demonstrates catching an exception thrown by a procedure call. */ #include #include using namespace std; /* The procedure a() throws an exception that it does not catch. */ void a() { printf("A is called, and is going to throw an exception:\n"); throw((string) "Exception in a()."); printf("This code does not get called.\n"); } /* Instead, main() catches the exception and prints out its argument. */ int main() { try { printf("Calling a()\n"); a(); printf("a() did not return, did it?\n"); } catch (const string &s) { printf("I caught an exception: %s\n", s.c_str()); } return 0; }