范例:
class MyMath {
public static int div(int x, int y) throws Exception {
int result = 0;
System.out.println("1.除法计算开始....");
try {
result = x / y;
} catch (Exception e) {
throw e;// 继续抛出异常
} finally {
System.out.println("2.除法计算结束....");
}
return result;
}
}
public class Test {
public static void main(String[] args) {
try {
System.out.println("计算结果:" + MyMath.div(10, 0));
} catch (Exception e) {
e.printStackTrace();
}
}
}