/** * Handles the specified {@code ExecutionException} and transforms it into a * runtime exception. This method works exactly like * {@link #handleCause(ExecutionException)}, but instead of a * {@link ConcurrentException} it throws a * {@link ConcurrentRuntimeException}. This is an alternative for client * code that does not want to deal with checked exceptions. * * @param ex the exception to be handled * @throws ConcurrentRuntimeException if the cause of the {@code * ExecutionException} is a checked exception; this exception is then * wrapped in the thrown runtime exception */ public static void handleCauseUnchecked(final ExecutionException ex) { final ConcurrentRuntimeException crex = extractCauseUnchecked(ex); if (crex != null) { throw crex; } }
/** * Tests extractCauseUnchecked() if the cause of the passed in exception is null. */ @Test public void testExtractCauseUncheckedNullCause() { assertNull("Non null result", ConcurrentUtils .extractCauseUnchecked(new ExecutionException("Test", null))); }
/** * Tests extractCauseUnchecked() for a null exception. */ @Test public void testExtractCauseUncheckedNull() { assertNull("Non null result", ConcurrentUtils.extractCauseUnchecked(null)); }
/** * Tests extractCauseUnchecked() if the cause is an unchecked exception. */ @Test public void testExtractCauseUncheckedUncheckedException() { final RuntimeException rex = new RuntimeException("Test"); try { ConcurrentUtils.extractCauseUnchecked(new ExecutionException(rex)); fail("Runtime exception not thrown!"); } catch (final RuntimeException r) { assertEquals("Wrong exception", rex, r); } }
/** * Tests extractCauseUnchecked() if the cause is a checked exception. */ @Test public void testExtractCauseUncheckedChecked() { final Exception ex = new Exception("Test"); final ConcurrentRuntimeException cex = ConcurrentUtils .extractCauseUnchecked(new ExecutionException(ex)); assertSame("Wrong cause", ex, cex.getCause()); }
/** * Tests extractCauseUnchecked() if the cause is an error. */ @Test public void testExtractCauseUncheckedError() { final Error err = new AssertionError("Test"); try { ConcurrentUtils.extractCauseUnchecked(new ExecutionException(err)); fail("Error not thrown!"); } catch (final Error e) { assertEquals("Wrong error", err, e); } }
/** * Handles the specified {@code ExecutionException} and transforms it into a * runtime exception. This method works exactly like * {@link #handleCause(ExecutionException)}, but instead of a * {@link ConcurrentException} it throws a * {@link ConcurrentRuntimeException}. This is an alternative for client * code that does not want to deal with checked exceptions. * * @param ex the exception to be handled * @throws ConcurrentRuntimeException if the cause of the {@code * ExecutionException} is a checked exception; this exception is then * wrapped in the thrown runtime exception */ public static void handleCauseUnchecked(final ExecutionException ex) { final ConcurrentRuntimeException crex = extractCauseUnchecked(ex); if (crex != null) { throw crex; } }
/** * Handles the specified {@code ExecutionException} and transforms it into a * runtime exception. This method works exactly like * {@link #handleCause(ExecutionException)}, but instead of a * {@link ConcurrentException} it throws a * {@link ConcurrentRuntimeException}. This is an alternative for client * code that does not want to deal with checked exceptions. * * @param ex the exception to be handled * @throws ConcurrentRuntimeException if the cause of the {@code * ExecutionException} is a checked exception; this exception is then * wrapped in the thrown runtime exception */ public static void handleCauseUnchecked(final ExecutionException ex) { final ConcurrentRuntimeException crex = extractCauseUnchecked(ex); if (crex != null) { throw crex; } }
/** * Handles the specified {@code ExecutionException} and transforms it into a * runtime exception. This method works exactly like * {@link #handleCause(ExecutionException)}, but instead of a * {@link ConcurrentException} it throws a * {@link ConcurrentRuntimeException}. This is an alternative for client * code that does not want to deal with checked exceptions. * * @param ex the exception to be handled * @throws ConcurrentRuntimeException if the cause of the {@code * ExecutionException} is a checked exception; this exception is then * wrapped in the thrown runtime exception */ public static void handleCauseUnchecked(final ExecutionException ex) { final ConcurrentRuntimeException crex = extractCauseUnchecked(ex); if (crex != null) { throw crex; } }