The only way that this will happen is the state of the system in question is available through any variables available above in the catch-catch chain or through the exception object itself (in the case of a custom exception):
public class MySpiffyException extends RuntimeException { final private int foo; final private String bar; public MySpiffyException(String message, int foo, String bar) { super(message); this.foo = foo; this.bar = bar; } public MySpiffyException(Throwable cause, int foo, String bar) { super(cause); this.foo = foo; this.bar = bar; } public int getFoo() { return this.foo; } public String getBar() { return this.bar; } } ... public void someCode() { ... int foo = ...; String bar = ...; if (foo > 0) throw new MySpiffyException(foo, bar); }
source share