summaryrefslogtreecommitdiff
path: root/gcc/testsuite/obj-c++.dg/try-catch-1.mm
blob: a32bfeed6e532ad1d2db987e425e85ff70830ec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* Test if the compiler accepts @throw / @try..@catch..@finally syntax.  */
/* Developed by Ziemowit Laski <zlaski@apple.com>.  */

/* { dg-options "-fobjc-exceptions" } */
/* { dg-do compile } */

#include "../objc-obj-c++-shared/Object1.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);
  }
}