zoukankan      html  css  js  c++  java
  • 异常-JDK7针对多个异常的处理方案

     1 package cn.itcast_02;
     2 
     3 /*
     4  * JDK7出现了一个新的异常处理方案:
     5  *         try{
     6  * 
     7  *         }catch(异常名1 | 异常名2 | ...  变量 ) {
     8  *             ...
     9  *         }
    10  * 
    11  *         注意:这个方法虽然简洁,但是也不够好。
    12  *            A:处理方式是一致的。(实际开发中,好多时候可能就是针对同类型的问题,给出同一个处理)
    13  *            B:多个异常间必须是平级关系。
    14  */
    15 public class ExceptionDemo3 {
    16     public static void main(String[] args) {
    17         method();
    18     }
    19 
    20     public static void method() {
    21         int a = 10;
    22         int b = 0;
    23         int[] arr = { 1, 2, 3 };
    24 
    25         // JDK7的处理方案
    26         try {
    27             System.out.println(a / b);
    28             System.out.println(arr[3]);
    29         } catch (ArithmeticException | ArrayIndexOutOfBoundsException e) {
    30             System.out.println("出问题了");
    31         }
    32 
    33         System.out.println("over");
    34     }
    35 
    36 }

  • 相关阅读:
    Linux ld命令
    Linux readelf命令
    linux ar命令
    Linux升级Ruby
    Linux dkpg命令
    Linux apt-get命令
    Linux xxd命令
    Linux objdump命令
    Linux ldconfig命令
    git 删除目录
  • 原文地址:https://www.cnblogs.com/ZHOUVIP/p/7220739.html
Copyright © 2011-2022 走看看