/** * Throws the original {@link IOException} if the given throwable is * a {@link TaggedIOException} decorator the given tag. Does nothing * if the given throwable is of a different type or if it is tagged * with some other tag. * <p> * This method is typically used in a <code>catch</code> block to * selectively rethrow tagged exceptions. * <pre> * Serializable tag = ...; * try { * ...; * } catch (Throwable t) { * TaggedIOExcepton.throwCauseIfTagged(t, tag); * // handle other kinds of exceptions * } * </pre> * * @param throwable an exception * @param tag tag object * @throws IOException original exception from the tagged decorator, if any */ public static void throwCauseIfTaggedWith(final Throwable throwable, final Object tag) throws IOException { if (isTaggedWith(throwable, tag)) { throw ((TaggedIOException) throwable).getCause(); } }
@Test public void testTaggedIOException() { final Serializable tag = UUID.randomUUID(); final IOException exception = new IOException("Test exception"); final TaggedIOException tagged = new TaggedIOException(exception, tag); assertTrue(TaggedIOException.isTaggedWith(tagged, tag)); assertFalse(TaggedIOException.isTaggedWith(tagged, UUID.randomUUID())); assertEquals(exception, tagged.getCause()); assertEquals(exception.getMessage(), tagged.getMessage()); }
/** * Throws the original {@link IOException} if the given throwable is * a {@link TaggedIOException} decorator the given tag. Does nothing * if the given throwable is of a different type or if it is tagged * with some other tag. * <p> * This method is typically used in a <code>catch</code> block to * selectively rethrow tagged exceptions. * <pre> * Serializable tag = ...; * try { * ...; * } catch (Throwable t) { * TaggedIOExcepton.throwCauseIfTagged(t, tag); * // handle other kinds of exceptions * } * </pre> * * @param throwable an exception * @param tag tag object * @throws IOException original exception from the tagged decorator, if any */ public static void throwCauseIfTaggedWith(final Throwable throwable, final Object tag) throws IOException { if (isTaggedWith(throwable, tag)) { throw ((TaggedIOException) throwable).getCause(); } }
/** * Throws the original {@link IOException} if the given throwable is * a {@link TaggedIOException} decorator the given tag. Does nothing * if the given throwable is of a different type or if it is tagged * with some other tag. * <p> * This method is typically used in a <code>catch</code> block to * selectively rethrow tagged exceptions. * <pre> * Serializable tag = ...; * try { * ...; * } catch (Throwable t) { * TaggedIOExcepton.throwCauseIfTagged(t, tag); * // handle other kinds of exceptions * } * </pre> * * @param throwable an exception * @param tag tag object * @throws IOException original exception from the tagged decorator, if any */ public static void throwCauseIfTaggedWith(final Throwable throwable, final Object tag) throws IOException { if (isTaggedWith(throwable, tag)) { throw ((TaggedIOException) throwable).getCause(); } }
/** * Throws the original {@link IOException} if the given throwable is * a {@link TaggedIOException} decorator the given tag. Does nothing * if the given throwable is of a different type or if it is tagged * with some other tag. * <p> * This method is typically used in a <code>catch</code> block to * selectively rethrow tagged exceptions. * <pre> * Serializable tag = ...; * try { * ...; * } catch (Throwable t) { * TaggedIOExcepton.throwCauseIfTagged(t, tag); * // handle other kinds of exceptions * } * </pre> * * @param throwable an exception * @param tag tag object * @throws IOException original exception from the tagged decorator, if any */ public static void throwCauseIfTaggedWith(Throwable throwable, Object tag) throws IOException { if (isTaggedWith(throwable, tag)) { throw ((TaggedIOException) throwable).getCause(); } }
/** * Throws the original {@link IOException} if the given throwable is * a {@link TaggedIOException} decorator the given tag. Does nothing * if the given throwable is of a different type or if it is tagged * with some other tag. * <p> * This method is typically used in a <code>catch</code> block to * selectively rethrow tagged exceptions. * <pre> * Serializable tag = ...; * try { * ...; * } catch (Throwable t) { * TaggedIOExcepton.throwCauseIfTagged(t, tag); * // handle other kinds of exceptions * } * </pre> * * @param throwable an exception * @param tag tag object * @throws IOException original exception from the tagged decorator, if any */ public static void throwCauseIfTaggedWith(Throwable throwable, Object tag) throws IOException { if (isTaggedWith(throwable, tag)) { throw ((TaggedIOException) throwable).getCause(); } }
exception = ((TaggedIOException) exception).getCause();