--- title: URIError slug: Web/JavaScript/Reference/Global_Objects/URIError translation_of: Web/JavaScript/Reference/Global_Objects/URIError ---
URIError 物件在全域的URI處理函式被錯誤使用時作為一個錯誤被拋出。
new URIError([message[, fileName[, lineNumber]]])
messagefileName {{non-standard_inline}}lineNumber {{non-standard_inline}}URIError 在全域的URI處理函式被傳入了一個錯誤編碼的URI時被拋出。
URIError 物件增加其屬性。普遍的 URIError 自身沒有包含方法,儘管他的確從原型鍊中繼承了一些。
URIError 物件實體URIErrortry {
decodeURIComponent('%');
} catch (e) {
console.log(e instanceof URIError); // true
console.log(e.message); // "malformed URI sequence"
console.log(e.name); // "URIError"
console.log(e.fileName); // "Scratchpad/1"
console.log(e.lineNumber); // 2
console.log(e.columnNumber); // 2
console.log(e.stack); // "@Scratchpad/2:2:3\n"
}
URIErrortry {
throw new URIError('Hello', 'someFile.js', 10);
} catch (e) {
console.log(e instanceof URIError); // true
console.log(e.message); // "Hello"
console.log(e.name); // "URIError"
console.log(e.fileName); // "someFile.js"
console.log(e.lineNumber); // 10
console.log(e.columnNumber); // 0
console.log(e.stack); // "@Scratchpad/2:2:9\n"
}
| 規範 | 狀態 | 註 |
|---|---|---|
| {{SpecName('ES3', '#sec-15.11.6.6', 'URIError')}} | {{Spec2('ES3')}} | Initial definition |
| {{SpecName('ES5.1', '#sec-15.11.6.6', 'URIError')}} | {{Spec2('ES5.1')}} | |
| {{SpecName('ES6', '#sec-native-error-types-used-in-this-standard-urierror', 'URIError')}} | {{Spec2('ES6')}} | |
| {{SpecName('ESDraft', '#sec-native-error-types-used-in-this-standard-urierror', 'URIError')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.URIError")}}