0

Java style guide: Avoid extraneous strings in Exceptions.

Change-Id: I34b87a55631eda7a76c5291c95444848c051b6cf
Reviewed-on: https://chromium-review.googlesource.com/1175861
Reviewed-by: Tommy Nyquist <nyquist@chromium.org>
Reviewed-by: Ted Choc <tedchoc@chromium.org>
Commit-Queue: agrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583309}
This commit is contained in:
agrieve
2018-08-15 17:49:16 +00:00
committed by Commit Bot
parent f9ccf6d16b
commit 50430de07a

@ -58,6 +58,22 @@ try {
}
```
* Avoid adding messages to exceptions that do not aid in debugging.
For example:
```java
try {
somethingThatThrowsIOException();
} catch (IOException e) {
// Bad - message does not tell you more than the stack trace does:
throw new RuntimeException("Failed to parse a file.", e);
// Good - conveys that this block failed along with the "caused by" exception.
throw new RuntimeException(e);
// Good - adds useful information.
throw new RuntimeException(String.format("Failed to parse %s", fileName), e);
}
```
### Logging
* Use `org.chromium.base.Log` instead of `android.util.Log`.
* It provides `%s` support, and ensures log stripping works correctly.