1. 程式人生 > >異常類Exception(String message, Throwable cause)中的cause理解

異常類Exception(String message, Throwable cause)中的cause理解

理解 cau sat spa clas con 初始化 use elf

  這個在構造函數裏面竟然有一個Throwable,感覺有些奇怪。

1.

  Throwable cause 這裏cause要傳一個Throwable的子類異常進去麽?

  是引起這個異常的異常,如果這個值是空值,那麽這個異常就是源頭;如果這個值等於自己,那麽這個異常還沒被初始化。

  /**
* The throwable that caused this throwable to get thrown, or null if this
* throwable was not caused by another throwable, or if the causative
* throwable is unknown. If this field is equal to this throwable itself,
* it indicates that the cause of this throwable has not yet been
* initialized.
*
* @serial
* @since 1.4
*/

異常類Exception(String message, Throwable cause)中的cause理解