diff options
Diffstat (limited to 'gcc/testsuite/objc.dg/try-catch-1.m')
-rw-r--r-- | gcc/testsuite/objc.dg/try-catch-1.m | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/gcc/testsuite/objc.dg/try-catch-1.m b/gcc/testsuite/objc.dg/try-catch-1.m new file mode 100644 index 00000000000..e40fdf85994 --- /dev/null +++ b/gcc/testsuite/objc.dg/try-catch-1.m @@ -0,0 +1,44 @@ +/* Test if the compiler accepts @throw / @try..@catch..@finally + syntax. This will only be usable on MacOS X 10.3 and later. */ +/* Developed by Ziemowit Laski <zlaski@apple.com>. */ +/* { dg-options "-fobjc-exceptions" } */ +/* { dg-do compile { target *-*-darwin* } } */ + +#include <objc/objc.h> +#include <objc/objc-runtime.h> +#include <objc/Object.h> +#include <stdio.h> +#include <setjmp.h> + +@interface Frob: Object +@end + +@implementation Frob: Object +@end + +static int exc_control = 0; + +int proc() { + if(exc_control) { + printf ("Throwing (%d)... ", exc_control); + @throw [Frob new]; + } + return 1; +} + +int foo() +{ + @try { + return proc(); + } + @catch (Frob* ex) { + if(exc_control > 1) { + printf("Rethrowing (%d)... ", exc_control); + @throw; + } + return 0; + } + @finally { + printf("In @finally block (%d)... ", exc_control); + } +} |