51 lines · plain
1// RUN: %check_clang_tidy %s google-objc-avoid-throwing-exception %t -- -- -I %S/Inputs/2 3@class NSString;4 5@interface NSException6 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 here9 10@end11 12@interface NotException13 14+ (void)raise:(NSString *)name format:(NSString *)format;15 16@end17 18@implementation Foo19- (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 e28 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@end50 51