class Math{
public int div(int i,int j) throws Exception{
System.out.println("======== 进行除法操作之前 ============") ;
int temp = 0 ;
try{
temp = i / j ;
}catch(Exception e){
throw e ; // 抛出异常
}finally{
System.out.println("======== 除法操作完成之后 ============") ;
}
return temp ;
}
};
public class Demo032{
public static void main(String args[]){
Math m = new Math() ;
try{
int temp = m.div(10,0) ;
System.out.println(temp) ;
}catch(Exception e){
System.out.println(e) ;
}
}
};
JavaLearning:异常

最新推荐文章于 2025-07-16 16:07:43 发布
