1// RUN: %check_clang_tidy %s google-objc-avoid-throwing-exception %t -- -- -I %S/Inputs/
2
3@class NSString;
4
5@interface NSException
6
7+ (void)raise:(NSString *)name format:(NSString *)format;
8+ (void)raise:(NSString *)name format:(NSString *)format arguments:(NSString *)args; // using NSString type since va_list cannot be recognized here
9
10@end
11
12@interface NotException
13
14+ (void)raise:(NSString *)name format:(NSString *)format;
15
16@end
17
18@implementation Foo
19- (void)f {
20 NSString *foo = @"foo";
21 @throw foo;
22 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception]
23}
24
25#include "system-header-throw.h"
26
27#define THROW(e) @throw e
28
29#define RAISE [NSException raise:@"example" format:@"fmt"]
30
31- (void)f2 {
32 [NSException raise:@"TestException" format:@"Test"];
33 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception]
34 [NSException raise:@"TestException" format:@"Test %@" arguments:@"bar"];
35 // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception]
36 [NotException raise:@"NotException" format:@"Test"];
37
38 NSException *e;
39 SYS_THROW(e);
40
41 SYS_RAISE;
42
43 THROW(e);
44 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception]
45
46 RAISE;
47 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: pass in NSError ** instead of throwing exception to indicate Objective-C errors [google-objc-avoid-throwing-exception]
48}
49@end
50
51

source code of clang-tools-extra/test/clang-tidy/checkers/google/objc-avoid-throwing-exception.m