Last active
August 29, 2015 14:24
-
-
Save a-r-d/b60ffe21c6fd99ac69c3 to your computer and use it in GitHub Desktop.
How exceptions work in Java
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
// Call some method that may throw an exception! | |
private void derp() throws Exception { | |
somethingDangerous(); | |
} | |
private void derpCaller() { | |
try { | |
derp(); | |
} catch (Exception e) { | |
// do something with exception and swallow it | |
} | |
} | |
private void derpCaller2() throws Exception{ | |
try { | |
derp(); | |
} catch (Exception e) { | |
// do something with exception BUT ALSO TRHOW IT! | |
// If you throw this here the method signature must state that an exception may be thrown! | |
throw e; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment