From 37c6d140179890707d2b309ab07020788a9e8f12 Mon Sep 17 00:00:00 2001 From: maciek Date: Wed, 3 Oct 2018 23:38:24 +0200 Subject: [PATCH] Replaced suggestion to use `Throwables.propagate` with suggestion to use Java 7 multi-catch. `Throwables.propagate` got deprecated for good reasons: https://github.com/google/guava/wiki/Why-we-deprecated-Throwables.propagate Skipped mentioning catching `Throwable`s since that do not fit into the context of this chapter. --- style/900_avoid_checked_exceptions.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/style/900_avoid_checked_exceptions.md b/style/900_avoid_checked_exceptions.md index 6a57702..e188c0b 100644 --- a/style/900_avoid_checked_exceptions.md +++ b/style/900_avoid_checked_exceptions.md @@ -26,15 +26,12 @@ try { } ``` -If you have caught an `Exception` or a `Throwable`, so are unsure of the exact type, you can avoid creating unnecessary wrappers using Guava's `Throwables.propagate`. +If you need to re-throw multiple checked exceptions that does not share common base other than `Exception`, to avoid unnecessary wrapping of runtime exceptions, you can use Java 7 multi-catch. ```java try { - myObject.methodThrowingException(); -} catch (Exception e) { - throw Throwables.propagate(e); + myObject.methodThrowingExceptions(); +} catch (SomeCheckedException | OtherCheckedException e) { + throw new RuntimeException(e); } ``` - -This will wrap checked exceptions and re-throw unchecked exception as is. -