1. 程式人生 > >java中異常(Exception)的定義,意義和用法。舉例

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

use 詳情 put 視頻下載 ati itl url index ring

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:優雅結束");
}
}

輸出結果:

Exception in thread "main" java.lang.ArithmeticException: / by zero
at Test.main(Test.java:4)

例: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)
{


。。。。。。。。。。。。。。。。。
詳情請進:http://www.mark-to-win.com/index.html?content=JavaBeginner/javaUrl.html&chapter=JavaBeginner/JavaBeginner5_web.html#PointDefinitionUsageException

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