Share via


description 屬性

更新:2007 年 11 月

傳回或設定與指定錯誤相關的描述字串。

 object.description

引數

  • object
    必要項。Error 物件的執行個體。

備註

description 屬性是一個包含與指定錯誤相關的錯誤訊息字串。請使用本屬性所含的值,以便在指令碼無法處理而發生錯誤時,用來警告使用者。

descriptionmessage 屬性參考相同的訊息;description 屬性提供向後相容性,而 message 屬性則符合 ECMA 標準。

範例

以下範例產生例外狀況 (Exception),並顯示該項錯誤的說明。

function getAge(age) {
   if(age < 0)
      throw new Error("An age cannot be negative.")
   print("Age is "+age+".");
}

// Pass the getAge an invalid argument.
try {
   getAge(-5);
} catch(e) {
   print(e.description);
}

本程式碼的輸出為:

An age cannot be negative.

需求

5 版

套用至:

Error 物件

請參閱

參考

number 屬性

message 屬性 (JScript)

name 屬性