代码: package yichang; public class Nuli{ public static void main(String[] args){ Nuli one = new Nuli(); try{ one.shuchu(); }catch(Xinde e){ System.out.println("123"); e.printStackTrace(); } } public void shuchu() throws Xinde{ int a = 10; int b = 0; if(a == 10){ a = a/b; } } }
自定义异常类:
package yichang;
public class Xinde extends Exception {
public Xinde(String me){
super(me);
}
}
其它都正常,就是不输出 123,哪位大神帮忙看看,谢谢了
你觉得如何?
你的异常类呢
这个可以输出123
package project6.immoc3;
public class show {
public static void main(String[] args) {
// TODO Auto-generated method stub
show mo=new show();
try{
mo.show1();
}catch(Exception e){
System.out.println("输出异常123");
e.printStackTrace();
}
}
public void show1() throws Exception{
int a=10;
int b=0;
if(a==10){
a=a/b;
}
}
}
package com.test;
public class ExceptionTest {
public static void main(String[] args) {
ExceptionTest one = new ExceptionTest();
try {
one.shuchu();
} catch (Exception e) {
System.out.println("123");
e.printStackTrace();
}
}
public void shuchu() {
int a = 10;
int b = 0;
if (a == 10) {
a = a / b;
}
}
}
public void shuchu() throws Xinde{
int a = 10;
int b = 0;
if(a == 10){
a = a/b;
}
}