- class ExceptionDemo3 {
- public static void main(String[] args){
- Demo d = new Demo();
- int f = d.div(5,0);
- System.out.println(f);
- }
- }
- class Demo {
- int div(int a,int b){
- try {
- if(b == 0)
- throw new Exception();
- }
- catch(Exception e){
- System.out.println(e.toString());
- System.out.println("除零啦");
- }
- return a/b;
- finally {
- System.out.println("over");
- }
-
- }
- }
复制代码 编译失败:
明明是有try的啊
什么原因呢
|