/** * Handles the specified {@code ExecutionException}. This method calls * {@link #extractCause(ExecutionException)} for obtaining the cause of the * exception - which might already cause an unchecked exception or an error * being thrown. If the cause is a checked exception however, it is wrapped * in a {@code ConcurrentException}, which is thrown. If the passed in * exception is <b>null</b> or has no cause, the method simply returns * without throwing an exception. * * @param ex the exception to be handled * @throws ConcurrentException if the cause of the {@code * ExecutionException} is a checked exception */ public static void handleCause(final ExecutionException ex) throws ConcurrentException { final ConcurrentException cex = extractCause(ex); if (cex != null) { throw cex; } }
/** * Tests extractCause() if the cause of the passed in exception is null. */ @Test public void testExtractCauseNullCause() { assertNull("Non null result", ConcurrentUtils .extractCause(new ExecutionException("Test", null))); }
/** * Tests extractCause() for a null exception. */ @Test public void testExtractCauseNull() { assertNull("Non null result", ConcurrentUtils.extractCause(null)); }
/** * Tests extractCause() if the cause is a checked exception. */ @Test public void testExtractCauseChecked() { final Exception ex = new Exception("Test"); final ConcurrentException cex = ConcurrentUtils .extractCause(new ExecutionException(ex)); assertSame("Wrong cause", ex, cex.getCause()); }
/** * Tests extractCause() if the cause is an error. */ @Test public void testExtractCauseError() { final Error err = new AssertionError("Test"); try { ConcurrentUtils.extractCause(new ExecutionException(err)); fail("Error not thrown!"); } catch (final Error e) { assertEquals("Wrong error", err, e); } }
/** * Tests extractCause() if the cause is an unchecked exception. */ @Test public void testExtractCauseUncheckedException() { final RuntimeException rex = new RuntimeException("Test"); try { ConcurrentUtils.extractCause(new ExecutionException(rex)); fail("Runtime exception not thrown!"); } catch (final RuntimeException r) { assertEquals("Wrong exception", rex, r); } }
/** * Handles the specified {@code ExecutionException}. This method calls * {@link #extractCause(ExecutionException)} for obtaining the cause of the * exception - which might already cause an unchecked exception or an error * being thrown. If the cause is a checked exception however, it is wrapped * in a {@code ConcurrentException}, which is thrown. If the passed in * exception is <b>null</b> or has no cause, the method simply returns * without throwing an exception. * * @param ex the exception to be handled * @throws ConcurrentException if the cause of the {@code * ExecutionException} is a checked exception */ public static void handleCause(final ExecutionException ex) throws ConcurrentException { final ConcurrentException cex = extractCause(ex); if (cex != null) { throw cex; } }
/** * Handles the specified {@code ExecutionException}. This method calls * {@link #extractCause(ExecutionException)} for obtaining the cause of the * exception - which might already cause an unchecked exception or an error * being thrown. If the cause is a checked exception however, it is wrapped * in a {@code ConcurrentException}, which is thrown. If the passed in * exception is <b>null</b> or has no cause, the method simply returns * without throwing an exception. * * @param ex the exception to be handled * @throws ConcurrentException if the cause of the {@code * ExecutionException} is a checked exception */ public static void handleCause(final ExecutionException ex) throws ConcurrentException { final ConcurrentException cex = extractCause(ex); if (cex != null) { throw cex; } }
/** * Handles the specified {@code ExecutionException}. This method calls * {@link #extractCause(ExecutionException)} for obtaining the cause of the * exception - which might already cause an unchecked exception or an error * being thrown. If the cause is a checked exception however, it is wrapped * in a {@code ConcurrentException}, which is thrown. If the passed in * exception is <b>null</b> or has no cause, the method simply returns * without throwing an exception. * * @param ex the exception to be handled * @throws ConcurrentException if the cause of the {@code * ExecutionException} is a checked exception */ public static void handleCause(final ExecutionException ex) throws ConcurrentException { final ConcurrentException cex = extractCause(ex); if (cex != null) { throw cex; } }