1 // RUN: %clang_cc1 -fsyntax-only -verify -fborland-extensions -fcxx-exceptions %s 2 // expected-no-diagnostics 3 4 // This test is from http://docwiki.embarcadero.com/RADStudio/en/Try 5 6 int puts(const char *); 7 8 template<typename T> 9 int printf(const char *, T); 10 11 const char * strdup(const char *); 12 13 void free(const void *); 14 15 #define EXCEPTION_EXECUTE_HANDLER 1 16 17 class Exception 18 { 19 public: Exception(const char * s="Unknown")20 Exception(const char* s = "Unknown"){what = strdup(s); } Exception(const Exception & e)21 Exception(const Exception& e ){what = strdup(e.what); } ~Exception()22 ~Exception() {free(what); } msg() const23 const char* msg() const {return what; } 24 private: 25 const char* what; 26 }; 27 main()28int main() 29 { 30 float e, f, g; 31 try 32 { 33 try 34 { 35 f = 1.0; 36 g = 0.0; 37 try 38 { 39 puts("Another exception:"); 40 41 e = f / g; 42 } 43 __except(EXCEPTION_EXECUTE_HANDLER) 44 { 45 puts("Caught a C-based exception."); 46 throw(Exception("Hardware error: Divide by 0")); 47 } 48 } 49 catch(const Exception& e) 50 { 51 printf("Caught C++ Exception: %s :\n", e.msg()); 52 } 53 } 54 __finally 55 { 56 puts("C++ allows __finally too!"); 57 } 58 return e; 59 } 60