Skip to content

Instantly share code, notes, and snippets.

@NickBaynham
Created February 13, 2019 13:42
Show Gist options
  • Save NickBaynham/76e0e04ef98cdd363c20ac02593b4ddd to your computer and use it in GitHub Desktop.
Save NickBaynham/76e0e04ef98cdd363c20ac02593b4ddd to your computer and use it in GitHub Desktop.
Exceptions
package codingExamples;
import org.junit.Test;
public class Exceptions2 {
@Test
public void test() {
System.out.println(doIt());
}
private int doIt() {
int i = 0; int j = 0;
try {
int k = i / j;
} catch (ArithmeticException e) {
return -1;
} catch (RuntimeException r) {
return 0;
} finally {
System.out.println("Done.");
}
return 1;
}
}
@NickBaynham
Copy link
Author

Output:
Done.
-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment