首页 > 编程语言 > 详细

java中异常(Exception)的定义,意义和用法。举例

时间:2021-03-02 10:59:43      阅读:22      评论:0      收藏:0      [点我收藏+]

1.异常(Exception)的定义,意义和用法 

我们先给出一个例子,看看异常有什么用?

例:1.1-

public class Test {
    public static void main(String[] args) {
        int userInput=0;
        int I = 6 / userInput;
        System.out.println("马克-to-win:优雅结束");
    }
}

 

例:1.1.2-

public class Test {
    public static void main(String[] args) {
        try
        {
            int userInput=0;
            int I = 6 / userInput;
            System.out.println("马克-to-win:inside try");
        }
/*系统把错误信息放在Exception的对象e中,马克-to-win*/        
        catch(Exception e)
        {
            System.out.println(e);
        }
        System.out.println("马克-to-win:优雅结束");
    }
}

 

更多内容请见原文,文章转载自:https://blog.csdn.net/qq_44639795/article/details/103109657

java中异常(Exception)的定义,意义和用法。举例

原文:https://www.cnblogs.com/shituxingzhe1949/p/14467790.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!