Exceptions
Last updated
public void divide(int a, int b) {
if (b == 0) {
throw new Exception("Error Message");
} else {
return a / b;
}
}public void divide2() {
int a = 0;
try {
return 10 / 0;
} catch(Exception e) {
System.out.println("oops!");
}
}static String tryCatchFinally() {
try {
System.out.println("trying");
throw new Exception();
} catch (Exception e) {
System.out.println("catching");
return "done catch";
} finally {
System.out.println("finally");
}
}static String tryFinally() {
try {
System.out.println("trying");
throw new Exception();
} finally {
System.out.println("finally");
}
}