Java Style Guide: Allow broad catches for IPC
These are common causes of stability bugs.
Also removes obsolete note about multi-catch statements.
These used to be unsupported on old android versions, but
have been supported now for so long that it's a bit odd to
mention them.
Bug: None
Change-Id: I357e8c3a2698deb6b789c22258f39bf421ceb0ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4133542
Reviewed-by: Tommy Nyquist <[email protected]>
Commit-Queue: Andrew Grieve <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1092427}
diff --git a/styleguide/java/java.md b/styleguide/java/java.md
index f6415f0..de8894b 100644
--- a/styleguide/java/java.md
+++ b/styleguide/java/java.md
@@ -65,24 +65,17 @@
## Other Language Features & APIs
### Exceptions
-* As with the Android style guide, we discourage overly broad catches via
-`Exception` / `Throwable` / `RuntimeException`.
- * If you need to have a broad catch expression, use a comment to explain why.
-* Catching multiple exceptions in one line is fine.
+We discourage overly broad catches via `Throwable`, `Exception`, or
+`RuntimeException`, except when dealing with `RemoteException` or similar
+system APIs.
+ * There have been many cases of crashes caused by `IllegalStateException` /
+ `IllegalArgumentException` / `SecurityException` being thrown where only
+ `RemoteException` was being caught. In these cases, use
+ `catch (RemoteException | RuntimeException e)`.
+ * For all broad catch expressions, add a comment to explain why.
-It is OK to do:
-```java
-try {
- somethingThatThrowsIOException(filePath);
- somethingThatThrowsParseException(filePath);
-} catch (IOException | ParseException e) {
- Log.w(TAG, "Failed to read: %s", filePath, e);
-}
-```
+Avoid adding messages to exceptions that do not aid in debugging. For example:
-* Avoid adding messages to exceptions that do not aid in debugging.
-
-For example:
```java
try {
somethingThatThrowsIOException();