• 异常处理try...catch


    package com.day16.Exception;
    /*
    * 异常处理的两种方式
    * 1.try...catch...finally
    * *try catch
    * *try catch finally
    * *try finally
    * 2.throws
    * try:用来检测异常的
    * catch:用来捕获异常的
    * finally:释放资源
    */

    public class ExceptionOne {

      public static void main(String[] args) {
        Demo d=new Demo();
        try {
          int x=d.div(10,0);
          System.out.println(x);
        }catch(ArithmeticException a) {//相当于ArithmeticException a=new ArithmeticException();
          System.out.println("除数为0了");//除数为0了
      }
      System.out.println("Kobe");//Kobe
      }

    }
    class Demo{
      public int div(int a,int b) {
        return a/b;
      }
    }

  • 相关阅读:
    fastdfs 外网映射问题记录
    fastdfs-nginx下载报错 400
    nginx 代理 websocket
    Jenkins 安装
    实验四.2
    实验四.1
    实验三
    shiyan2
    shiyan1
    作业
  • 原文地址:https://www.cnblogs.com/zhujialei123/p/9043484.html
Copyright © 2020-2023  润新知