java自定義異常類===代碼問題
代碼: 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,哪位大神幫忙看看,謝謝了
2018-12-23
2017-07-01
你的異常類呢
2017-07-01
這個可以輸出123
2017-07-01
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;
}
}
}
2017-03-24
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;
?? ??? ?}
?? ?}
}
2017-03-24
public void shuchu() throws Xinde{
?? ?? int a = 10;
?? ?? int b = 0;
?? ?? if(a == 10){
?? ??? a = a/b;
?? ?? }
?? ? }