Commit 50430de0 authored by agrieve's avatar agrieve Committed by Commit Bot

Java style guide: Avoid extraneous strings in Exceptions.

Change-Id: I34b87a55631eda7a76c5291c95444848c051b6cf
Reviewed-on: https://chromium-review.googlesource.com/1175861Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Commit-Queue: agrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583309}
parent f9ccf6d1
...@@ -58,6 +58,22 @@ try { ...@@ -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 ### Logging
* Use `org.chromium.base.Log` instead of `android.util.Log`. * Use `org.chromium.base.Log` instead of `android.util.Log`.
* It provides `%s` support, and ensures log stripping works correctly. * It provides `%s` support, and ensures log stripping works correctly.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment