@Test public void nestedSQLException() { SQLException origNestedEx = createSQLException("blablubbxxx"); RuntimeException origEx = createRuntimeException(origNestedEx); assertThat(origEx.getMessage()).isEqualTo("java.sql.SQLException: blablubbxxx"); Error error = new Error(origEx); try { RemoteExceptionUtil.throwOriginalExceptionIfPossible(error); } catch (Exception newEx) { newEx.printStackTrace(); assertThat(newEx).isInstanceOf(RuntimeException.class); assertThat(newEx.getMessage()).isEqualTo("java.sql.SQLException: blablubbxxx"); assertThat(newEx.getCause()).isNotNull(); assertThat(newEx.getCause()).isInstanceOf(SQLException.class); assertThat(newEx.getCause().getMessage()).isEqualTo("blablubbxxx"); } }
public static void throwOriginalExceptionIfPossible(final Error error) { Throwable throwable = toThrowable(error); if (throwable instanceof RuntimeException) throw (RuntimeException) throwable; if (throwable instanceof java.lang.Error) throw (java.lang.Error) throwable; throw new RuntimeException(throwable); }
RemoteExceptionUtil { public static void throwOriginalExceptionIfPossible(final Error error) { Throwable throwable = toThrowable(error); if (throwable instanceof RuntimeException) throw (RuntimeException) throwable; if (throwable instanceof java.lang.Error) throw (java.lang.Error) throwable; throw new RuntimeException(throwable); } }
RemoteExceptionUtil { public static void throwOriginalExceptionIfPossible(final Error error) { Throwable throwable = toThrowable(error); if (throwable instanceof RuntimeException) throw (RuntimeException) throwable; if (throwable instanceof java.lang.Error) throw (java.lang.Error) throwable; throw new RuntimeException(throwable); } private  RemoteExceptionUtil(); }
RemoteExceptionUtil { public static void throwOriginalExceptionIfPossible(final Error error) { Throwable throwable = toThrowable(error); if (throwable instanceof RuntimeException) throw (RuntimeException) throwable; if (throwable instanceof java.lang.Error) throw (java.lang.Error) throwable; throw new RuntimeException(throwable); } private  RemoteExceptionUtil(); static void throwOriginalExceptionIfPossible(final Error error); }
RemoteExceptionUtil { public static void throwOriginalExceptionIfPossible(final Error error) { Throwable throwable = toThrowable(error); if (throwable instanceof RuntimeException) throw (RuntimeException) throwable; if (throwable instanceof java.lang.Error) throw (java.lang.Error) throwable; throw new RuntimeException(throwable); } private  RemoteExceptionUtil(); static void throwOriginalExceptionIfPossible(final Error error);  }