35 异常

 

例子:

 1 package com.snape.java.ExceptionProj;
 2 
 3 public class ExceptionTest {
 4     public static void main(String[] args) {
 5         try{
 6             int a = 112;
 7             int b = 20;
 8             System.out.println("a/b = " + a/b);
 9         }catch (Exception e){  //可设置多重catch结构
10             System.out.println("程序出错");
11             e.printStackTrace();
12         }finally {  //无论是否有异常都会执行finally块内的内容
13             System.out.println("运算结束");
14         }
15     }
16 }

结果:

 (有异常时):

关于return:

猜你喜欢

转载自www.cnblogs.com/CPU-Easy/p/12177623.html
35