OSDN Git Service

2010-03-25 Iain Sandoe <iain.sandoe@sandoe-acoustics.co.uk>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / try-catch-1.m
1 /* Test if the compiler accepts @throw / @try..@catch..@finally syntax.  */
2 /* Developed by Ziemowit Laski <zlaski@apple.com>.  */
3 /* { dg-options "-fobjc-exceptions" } */
4 /* { dg-do compile } */
5
6 #include "../objc-obj-c++-shared/Object1.h"
7 #include <stdio.h>
8 #include <setjmp.h>
9
10 @interface Frob: Object
11 @end
12
13 @implementation Frob: Object
14 @end
15
16 static int exc_control = 0;
17
18 int proc() {
19   if(exc_control) {
20     printf ("Throwing (%d)... ", exc_control);
21     @throw [Frob new];
22   }
23   return 1;
24 }
25
26 int foo()
27 {
28         @try {
29                 return proc();
30         }
31         @catch (Frob* ex) {
32                 if(exc_control > 1) {
33                   printf("Rethrowing (%d)... ", exc_control);
34                   @throw;
35                 }
36                 return 0;
37         }
38         @finally {
39                 printf("In @finally block (%d)... ", exc_control);
40         }
41 }