If I run the following test, it fails:
public class CrazyExceptions {
private Exception exception;
@Before
public void setUp(){
exception =
You wouldn't want throwing an exception to alter the stack track or you couldn't re-throw an exception safely.
public void throwsException() {
throw new RuntimeException();
}
public void logsException() {
try {
throwsException();
} catch (RuntimeException e) {
e.printStrackTrace();
throw e; // doesn't alter the exception.
}
}
@Test
public void youCanSeeTheCauseOfAnException(){
try {
logsException();
} catch(Exception e) {
e.printStrackTrace(); // shows you the case of the exception, not where it was last re-thrown.
}
}