62,615
社区成员
发帖
与我相关
我的任务
分享
package var;
public class ExceptionTest9// 自定义异常练习
{
public static void main(String[] args) {
Test t = new Test();
int x=0;
try {
x = t.div(4, -1);
} catch (fushuException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("x=" + x);
}
}
class fushuException extends Exception {
}
class Test {
int div(int a, int b) throws fushuException {
if (b < 0)
throw new fushuException();
return a / b;
}
}
var.fushuException
at var.Test.div(ExceptionTest9.java:24)
at var.ExceptionTest9.main(ExceptionTest9.java:8)
x=0