@Test public void testSQLExceptionChain() throws Exception { ClassLoader cl = new URLClassLoader(new URL[] {UnitTestUtil.getTestDataFile("test.jar").toURI().toURL()}); Exception obj = (Exception)ReflectionHelper.create("test.UnknownException", null, cl); SQLException se = new SQLException("something bad happened"); se.initCause(obj); SQLException next = se; for (int i = 0; i < 10; i++) { SQLException se1 = new SQLException("something else bad happened"); se1.initCause(obj); next.setNextException(se1); next = se1; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); CustomStream oos = new CustomStream(baos); oos.writeObject(new ExceptionHolder(se, false)); oos.flush(); assertEquals(22, oos.count.get()); ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())); ExceptionHolder holder = (ExceptionHolder)ois.readObject(); Throwable e = holder.getException(); assertTrue(e instanceof SQLException); assertEquals("Remote java.sql.SQLException: something bad happened", e.getMessage()); assertTrue(e.getCause() instanceof TeiidRuntimeException); e = ((SQLException)e).getNextException(); assertTrue(e instanceof SQLException); assertEquals("Remote java.sql.SQLException: something else bad happened", e.getMessage()); int count = 0; while ((e = ((SQLException)e).getNextException()) != null) { count++; } assertEquals(9, count); }
public Throwable getException() { return exception; }
ExceptionHolder implements Externalizable { public Throwable getException() { return exception; } }
ExceptionHolder implements Externalizable { public Throwable getException() { return exception; } ExceptionHolder();  ExceptionHolder(Throwable exception);  ExceptionHolder(Throwable exception, boolean nested); }
ExceptionHolder implements Externalizable { public Throwable getException() { return exception; } ExceptionHolder();  ExceptionHolder(Throwable exception);  ExceptionHolder(Throwable exception, boolean nested); @Override void readExternal(ObjectInput in); @Override void writeExternal(ObjectOutput out); Throwable getException(); static List<ExceptionHolder> toExceptionHolders(List<? extends Throwable> throwables); static List<Throwable> toThrowables(List<ExceptionHolder> exceptionHolders); }
ExceptionHolder implements Externalizable { public Throwable getException() { return exception; } ExceptionHolder();  ExceptionHolder(Throwable exception);  ExceptionHolder(Throwable exception, boolean nested); @Override void readExternal(ObjectInput in); @Override void writeExternal(ObjectOutput out); Throwable getException(); static List<ExceptionHolder> toExceptionHolders(List<? extends Throwable> throwables); static List<Throwable> toThrowables(List<ExceptionHolder> exceptionHolders);  }