Java 实例 - 重载方法异常处理
Java 教程
· 2019-02-11 10:59:25
以下实例演示了重载方法的异常处理:
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
点击查看所有 Java 教程 文章: https://codercto.com/courses/l/12.html
在你身边,为你设计
腾讯公司用户研究与体验设计部 / 电子工业出版社 / 2013-1 / 69.00元
设计属于所有人,也意在为所有人使用,这既是设计的价值,也是设计的责任。本书内容包括:设计理念、设计方法、用户研究、体验设计、设计流程和工具,以及团队成长与管理等方面的知识与经验分享。一起来看看 《在你身边,为你设计》 这本书的介绍吧!