Skip to content

Instantly share code, notes, and snippets.

@Tarrasch
Created November 8, 2013 13:59
Show Gist options
  • Save Tarrasch/7371407 to your computer and use it in GitHub Desktop.
Save Tarrasch/7371407 to your computer and use it in GitHub Desktop.
Example where exception values can escape their handlers in java
public class Main {
public static void main(String[] args) {
Exception e2 = new Exception();
try {
test();
}
catch (Exception e) {
e2 = e;
}
e2.printStackTrace(); // The exception value is used outside of it's handler
}
public static int test() {
return 1/0;
}
}
/*
$ javac Main.java && java Main
java.lang.ArithmeticException: / by zero
at Main.test(Main.java:15)
at Main.main(Main.java:5)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment