Skip to content

Instantly share code, notes, and snippets.

@a-r-d
Last active August 29, 2015 14:24
Show Gist options
  • Save a-r-d/b60ffe21c6fd99ac69c3 to your computer and use it in GitHub Desktop.
Save a-r-d/b60ffe21c6fd99ac69c3 to your computer and use it in GitHub Desktop.
How exceptions work in Java
// 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