brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1017 B · bd099c4 Raw
41 lines · plain
1.. title:: clang-tidy - google-objc-avoid-throwing-exception2 3google-objc-avoid-throwing-exception4====================================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 throwing9exceptions from Objective-C code.10 11The corresponding C++ style guide rule:12https://google.github.io/styleguide/cppguide.html#Exceptions13 14Instead, prefer passing in ``NSError **`` and return ``BOOL`` to indicate15success or failure.16 17A counterexample:18 19.. code-block:: objc20 21  - (void)readFile {22    if ([self isError]) {23      @throw [NSException exceptionWithName:...];24    }25  }26 27Instead, returning an error via ``NSError **`` is preferred:28 29.. code-block:: objc30 31  - (BOOL)readFileWithError:(NSError **)error {32    if ([self isError]) {33      *error = [NSError errorWithDomain:...];34      return NO;35    }36    return YES;37  }38 39The corresponding style guide rule:40https://google.github.io/styleguide/objcguide.html#avoid-throwing-exceptions41