private static <T extends Exception> T initCause(T e, Object... arguments) { int size = arguments.length; if (size > 0) { Object o = arguments[size - 1]; if (o instanceof Throwable) { e.initCause((Throwable) o); } } return e; }
/** * Initializes the cause of this exception to the specified value. * * @param cause The cause of this exception. * @return This exception. * @throws IllegalArgumentException If the specified cause is this * exception. * @throws IllegalStateException If the cause of this exception has already * been set. * @since 1.3 */ @Override public Throwable initCause(Throwable cause) { return super.initCause(cause); }
/** * Initializes the cause of this exception to the specified value. * * @param cause The cause of this exception. * @return This exception. * @throws IllegalArgumentException If the specified cause is this * exception. * @throws IllegalStateException If the cause of this exception has already * been set. * @since 1.3 */ @Override public Throwable initCause(Throwable cause) { return super.initCause(cause); } }
/** * Initializes the cause of this exception to the specified value. * * @param cause The cause of this exception. * @return This exception. * @throws IllegalArgumentException If the specified cause is this * exception. * @throws IllegalStateException If the cause of this exception has already * been set. * @since 1.1 */ public Throwable initCause(Throwable cause) { return super.initCause(cause); }
/** * Initializes the cause of this exception to the specified value. * * @param cause The cause of this exception. * @return This exception. * @throws IllegalArgumentException If the specified cause is this * exception. * @throws IllegalStateException If the cause of this exception has already * been set. * @since 1.0.1 */ public Throwable initCause(Throwable cause) { return super.initCause(cause); }
/** * Initializes the cause of this exception to the specified value. * * @param cause The cause of this exception. * @return This exception. * @throws IllegalArgumentException If the specified cause is this * exception. * @throws IllegalStateException If the cause of this exception has already * been set. * @since 1.1 */ public Throwable initCause(Throwable cause) { return super.initCause(cause); } }
/** * Initializes the cause of this exception to the specified value. * * @param cause The cause of this exception. * @return This exception. * @throws IllegalArgumentException If the specified cause is this * exception. * @throws IllegalStateException If the cause of this exception has already * been set. * @since 1.2 */ public Throwable initCause(Throwable cause) { return super.initCause(cause); } }
/** * Initializes the cause of this exception to the specified value. * * @param cause The cause of this exception. * @return This exception. * @throws IllegalArgumentException If the specified cause is this * exception. * @throws IllegalStateException If the cause of this exception has already * been set. * @since 1.2 */ public Throwable initCause(Throwable cause) { return super.initCause(cause); } }
private static <T extends Exception> T initCause(T e, Object... arguments) { int size = arguments.length; if (size > 0) { Object o = arguments[size - 1]; if (o instanceof Exception) { e.initCause((Exception) o); } } return e; }
public synchronized void abort(Throwable cause) { interrupted = new AbortException(); if (cause!=null) interrupted.initCause(cause); notifyAll(); }
private static <X extends Exception> X newWithCause(Class<X> exceptionClass, Throwable cause) { // getConstructors() guarantees this as long as we don't modify the array. @SuppressWarnings({"unchecked", "rawtypes"}) List<Constructor<X>> constructors = (List) Arrays.asList(exceptionClass.getConstructors()); for (Constructor<X> constructor : preferringStrings(constructors)) { @Nullable X instance = newFromConstructor(constructor, cause); if (instance != null) { if (instance.getCause() == null) { instance.initCause(cause); } return instance; } } throw new IllegalArgumentException( "No appropriate constructor for exception of type " + exceptionClass + " in response to chained exception", cause); }
private static <X extends Exception> X newWithCause(Class<X> exceptionClass, Throwable cause) { // getConstructors() guarantees this as long as we don't modify the array. @SuppressWarnings({"unchecked", "rawtypes"}) List<Constructor<X>> constructors = (List) Arrays.asList(exceptionClass.getConstructors()); for (Constructor<X> constructor : preferringStrings(constructors)) { @NullableDecl X instance = newFromConstructor(constructor, cause); if (instance != null) { if (instance.getCause() == null) { instance.initCause(cause); } return instance; } } throw new IllegalArgumentException( "No appropriate constructor for exception of type " + exceptionClass + " in response to chained exception", cause); }
private static <X extends Exception> X newWithCause(Class<X> exceptionClass, Throwable cause) { // getConstructors() guarantees this as long as we don't modify the array. @SuppressWarnings({"unchecked", "rawtypes"}) List<Constructor<X>> constructors = (List) Arrays.asList(exceptionClass.getConstructors()); for (Constructor<X> constructor : preferringStrings(constructors)) { @NullableDecl X instance = newFromConstructor(constructor, cause); if (instance != null) { if (instance.getCause() == null) { instance.initCause(cause); } return instance; } } throw new IllegalArgumentException( "No appropriate constructor for exception of type " + exceptionClass + " in response to chained exception", cause); }
public void testGetRootCause_Loop() { Exception cause = new Exception(); Exception exception = new Exception(cause); cause.initCause(exception); try { Throwables.getRootCause(cause); fail("Should have throw IAE"); } catch (IllegalArgumentException expected) { assertThat(expected).hasCauseThat().isSameAs(cause); } }
/** * . */ @Test public void testCircularCauseExceptions() { final Exception e1 = new Exception(); final Exception e2 = new Exception(e1); e1.initCause(e2); LogManager.getLogger().error("Error", e1); } }
public void testGetCasualChainLoop() { Exception cause = new Exception(); Exception exception = new Exception(cause); cause.initCause(exception); try { Throwables.getCausalChain(cause); fail("Should have throw IAE"); } catch (IllegalArgumentException expected) { assertThat(expected).hasCauseThat().isSameAs(cause); } }
public void testExceptionConversion() { Exception ex1 = createException(); ex1.initCause(createSimpleCause()); Throwable ex = HiveSQLException.toCause(HiveSQLException.toString(ex1)); Assert.assertSame(RuntimeException.class, ex.getClass()); Assert.assertEquals("exception1", ex.getMessage()); Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass()); Assert.assertEquals("exception2", ex.getCause().getMessage()); } };
@Test public void shouldHandleRecursiveExceptionChain() { final Exception cause = new TestException("Something went wrong"); final Throwable e = new TestException("Top level", cause); cause.initCause(e); assertThat( buildErrorMessage(e), is("Top level" + System.lineSeparator() + "Caused by: Something went wrong") ); }
/** * Tests the conversion between the exception text with the simple cause and the * Throwable object */ @Test public void testExceptionMarshalling() throws Exception { Exception ex1 = createException(); ex1.initCause(createSimpleCause()); Throwable ex = HiveSQLException.toCause(HiveSQLException.toString(ex1)); Assert.assertSame(RuntimeException.class, ex.getClass()); Assert.assertEquals("exception1", ex.getMessage()); Assert.assertSame(UnsupportedOperationException.class, ex.getCause().getClass()); Assert.assertEquals("exception2", ex.getCause().getMessage()); }
/** * Tests the conversion from a regular exception to the TStatus object */ @Test public void testExceptionToTStatus() { Exception ex1 = createException(); ex1.initCause(createSimpleCause()); TStatus status = HiveSQLException.toTStatus(ex1); Assert.assertEquals(TStatusCode.ERROR_STATUS, status.getStatusCode()); Assert.assertEquals(ex1.getMessage(), status.getErrorMessage()); Assert.assertEquals(HiveSQLException.toString(ex1), status.getInfoMessages()); }