Skip to content

Commit dec4906

Browse files
author
Justin Lin
committed
formatting
1 parent 675d6b9 commit dec4906

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

docs/CH10.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,24 +280,22 @@ Error 類別與 Exception 類別都繼承自 Throwable 類別,Throwable 類別
280280

281281
您所接觸的例外通常都是衍生自 Exception 類別,其中是有些「受檢例外」(Checked exception),例如 ClassNotFoundException(嘗試載入類別時失敗所引發,例如類別檔案不存在)、InterruptedException(執行緒非執行中而嘗試中斷所引發的例外)等,而有些是「執行時期例外」(Runtime exception),也稱「非受檢例外」(Unckecked exception),例如 ArithmeticException、ArrayIndexOutOfBoundsException 等。以下列出一些重要的例外繼承架構:
282282

283-
```java
284-
Throwable
285-
  Error(嚴重的系統錯誤)
286-
    LinkageError
287-
    ThreadDeath
288-
    VirtualMachineError
289-
    ....
290-
  Exception
291-
    ClassNotFoundException
292-
    CloneNotSupportedException
293-
    IllegalAccessException
294-
    ....
295-
    RuntimeException(執行時期例外)
296-
      ArithmeticException
297-
      ArrayStoreException
298-
      ClassCastException
299-
      ....
300-
```
283+
Throwable
284+
  Error(嚴重的系統錯誤)
285+
    LinkageError
286+
    ThreadDeath
287+
    VirtualMachineError
288+
    ....
289+
  Exception
290+
    ClassNotFoundException
291+
    CloneNotSupportedException
292+
    IllegalAccessException
293+
    ....
294+
    RuntimeException(執行時期例外)
295+
      ArithmeticException
296+
      ArrayStoreException
297+
      ClassCastException
298+
      ....
301299

302300
Exception 下非 RuntimeException 衍生之例外類別如果有引發的可能,則您一定要在程式中明確的指定處理才可以通過編譯,因為這些例外是可預期的,編譯器會要求您明確處理,所以才稱之為「受檢例外」(Checked exception),例如當您使用到 BufferedReader 的 readLine() 時,由於有可能引發 IOException 這個受檢例外,您要不就在 try...catch 中處理,要不就在方法上使用 "throws" 表示由呼叫它的呼叫者來處理。
303301

0 commit comments

Comments
 (0)