Created
November 8, 2013 13:59
-
-
Save Tarrasch/7371407 to your computer and use it in GitHub Desktop.
Example where exception values can escape their handlers in java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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