URIError() コンストラクター
Baseline
広く利用可能
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2015年7月以降、すべてのブラウザーで利用可能です。
URIError コンストラクターは、グローバルの URI 操作関数が間違った方法で使用された場合のエラーを生成します。
構文
new URIError([message[, fileName[, lineNumber]]])
引数
message省略可-
人間が読むためのエラーの説明です。
fileName省略可-
例外が発生したコードを含むファイルの名前です。
lineNumber省略可-
例外が発生したコードの行番号です。
例
>URIError の捕捉
js
try {
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"
}
URIError の生成
js
try {
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"
}
仕様書
| 仕様書 |
|---|
| ECMAScript® 2027 Language Specification> # sec-nativeerror-constructors> |
ブラウザーの互換性
ブラウザー互換性一覧表を表示するには、JavaScript を有効にしてください。