案例一
package Lei;
public class StringDemo {
public static void main(String[] args)
{
try {
tell(10,0);
} catch (ArithmeticException e) {
// TODO Auto-generated catch block
System.out.println(e);
}
}
//将异常抛给主函数 主函数需要 捕获 并处理异常才行 如果主函数 业抛出异常那么 就由JVM处理
public static void tell(int i,int j)throws ArithmeticException
{
int t =0;
t=i/j;
System.out.println(t);
}
}
结果如下:
java.lang.ArithmeticException: / by zero