java中異常(Exception)的定義,意義和用法。舉例


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM