1//===-- main.m ------------------------------------------------*- ObjC -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#import <Foundation/Foundation.h>
10
11#import <exception>
12#import <stdexcept>
13
14@interface MyCustomException: NSException
15@end
16@implementation MyCustomException
17@end
18
19void foo(int n)
20{
21    NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:@"some_value", @"some_key", nil];
22    switch (n) {
23        case 0:
24            @throw [[NSException alloc] initWithName:@"ThrownException" reason:@"SomeReason" userInfo:info];
25        case 1:
26            @throw [[MyCustomException alloc] initWithName:@"ThrownException" reason:@"SomeReason" userInfo:info];
27        case 2:
28            throw std::runtime_error("C++ exception");
29    }
30}
31
32void rethrow(int n)
33{
34    @try {
35        foo(n);
36    } @catch(NSException *e) {
37        @throw;
38    }
39}
40
41int main(int argc, const char * argv[])
42{
43    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
44
45    NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:@"some_value", @"some_key", nil];
46    NSException *e1 = [[NSException alloc] initWithName:@"ExceptionName" reason:@"SomeReason" userInfo:info];
47    NSException *e2;
48
49    @try {
50        foo(atoi(argv[1]));
51    } @catch(NSException *e) {
52        e2 = e;
53    }
54
55    NSLog(@"1"); // Set break point at this line.
56
57    rethrow(atoi(argv[1]));
58
59    [pool drain];
60    return 0;
61}
62
63