2010年4月16日 星期五

JAVA筆記-擷取例外的類別

Throwable
     <- Error (Compiler會自己找出來)
     <- Exception (由try-catch擷取例外)

Exception
     <- ClassNotFoundException
     <- SQLException
     <- InterruptedException
     <- IOException <- EOFException
                            <- FileNotFoundException
     <- RuntimeException <- ArithmeticException(除以零)
                                     <- NullPointerException
                                     <- IndexOutOfBoundsException
                                     <- IllegalStateException
                                     <- ClassCastException
                                     <- IllegalArgumentException

IndexOutOfBoundsException
     <- NumberFormatException

IllegalStateException
     <- ArrayIndexOutOfBoundsException

使用範例:
try {
  // 可能發生例外的程式碼
}
catch (ArithmeticException e){
  // 發生例外時處理的程式碼
}

0 意見 :

張貼留言