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