Java 实例 – 重载方法异常处理
2021-04-23 00:29
                         标签:tps   method   top   com   处理   异常处理   tle   ott   author    Java 实例 - 重载方法异常处理  Java 实例 以上代码运行输出结果为:  Java 实例 Java 实例 – 重载方法异常处理 标签:tps   method   top   com   处理   异常处理   tle   ott   author    原文地址:https://www.cnblogs.com/breakyizhan/p/13272654.html
以下实例演示了重载方法的异常处理:Main.java 文件
public class Main {
double method(int i) throws Exception{
return i/0;
    }
boolean method(boolean b) {
return !b;
    }
static double method(int x, double y) throws Exception {
return x + y ;
    }
static double method(double x, double y) {
return x + y - 3;
    }
public static void main(String[] args) {
Main mn = new Main();
        try{
System.out.println(method(10, 20.0));
            System.out.println(method(10.0, 20));
            System.out.println(method(10.0, 20.0));
            System.out.println(mn.method(10));
        }
catch (Exception ex){
System.out.println("exception occoure: "+ ex);
        }
}
}
30.0
27.0
27.0
exception occoure: java.lang.ArithmeticException: / by zero
下一篇:先排序,后取前xx条数据