zoukankan      html  css  js  c++  java
  • throws与throw关键字。

    使用throws声明的方法表示此方法不处理异常,而是交给方法的调用处进行处理;

    public class Math {
    public int div(int i,int j)throws Exception{
    System.out.println("********计算开始********");
    int temp = 0;
    try {
    temp = i/j;
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    System.out.println("********计算结束********");
    }
    return temp;
    }
    }

    --------------------------------------------------------------
    public class ThrowsTest {
    public static void main(String[] args) {
    Math m = new Math();
    try {
    System.out.println(m.div(0,0));
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }

    throw可以直接抛出一个异常,抛出时直接抛出异常类的实例化对象即可。 

  • 相关阅读:
    thinkphp目录解析
    开发规范
    form
    命名空间
    类与对象
    OS知识点汇总
    C++每日一记!
    语言哲学和语言逻辑
    形式语言与自动机
    C#脚本
  • 原文地址:https://www.cnblogs.com/wangffeng293/p/13389819.html
Copyright © 2011-2022 走看看