Last active
December 16, 2015 10:29
-
-
Save serac/5420655 to your computer and use it in GitHub Desktop.
Demonstrate that catching an exception in a finally block does not consume the exception thrown from the outer try block.
This file contains 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
import java.io.BufferedReader; | |
import java.io.InputStreamReader; | |
import java.io.IOException; | |
public class FinallyThrowsTest { | |
public static void main(final String[] args) { | |
try { | |
throw new RuntimeException("Thrown from outer try"); | |
} finally { | |
try { | |
throw new RuntimeException("Thrown from try/catch inside finally."); | |
} catch (Exception e) { | |
System.out.println("Caught an exception in finally: " + e.getMessage()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment