1.. title:: clang-tidy - google-objc-avoid-throwing-exception 2 3google-objc-avoid-throwing-exception 4==================================== 5 6Finds uses of throwing exceptions usages in Objective-C files. 7 8For the same reason as the Google C++ style guide, we prefer not throwing 9exceptions from Objective-C code. 10 11The corresponding C++ style guide rule: 12https://google.github.io/styleguide/cppguide.html#Exceptions 13 14Instead, prefer passing in ``NSError **`` and return ``BOOL`` to indicate success or failure. 15 16A counterexample: 17 18.. code-block:: objc 19 20 - (void)readFile { 21 if ([self isError]) { 22 @throw [NSException exceptionWithName:...]; 23 } 24 } 25 26Instead, returning an error via ``NSError **`` is preferred: 27 28.. code-block:: objc 29 30 - (BOOL)readFileWithError:(NSError **)error { 31 if ([self isError]) { 32 *error = [NSError errorWithDomain:...]; 33 return NO; 34 } 35 return YES; 36 } 37 38The corresponding style guide rule: 39https://google.github.io/styleguide/objcguide.html#avoid-throwing-exceptions 40