JavaLearning:异常

来源:互联网 发布:单片机元器件清单 编辑:程序博客网 时间:2024/04/30 05:44
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) ;}}};

0 0