URIError() コンストラクター
Baseline
広く利用可能
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2015年7月以降、すべてのブラウザーで利用可能です。
URIError コンストラクターは URIError オブジェクトを生成します。
構文
js
new URIError()
new URIError(message)
new URIError(message, options)
new URIError(message, fileName)
new URIError(message, fileName, lineNumber)
URIError()
URIError(message)
URIError(message, options)
URIError(message, fileName)
URIError(message, fileName, lineNumber)
メモ:
URIError() は new があってもなくても呼び出せます。どちらも新しい URIError インスタンスを生成します。
引数
message省略可-
人間が読むためのエラーの説明です。
options省略可-
以下のプロパティを持つオブジェクトです。
cause省略可-
エラーの具体的な原因を示すプロパティです。 エラーを捕捉し、より具体的または有用なエラーメッセージを付けて再度投げる場合、このプロパティを使用して元のエラーを渡すことができます。
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.stack); // このエラーのスタック
}
URIError の生成
js
try {
throw new URIError("Hello");
} catch (e) {
console.log(e instanceof URIError); // true
console.log(e.message); // "Hello"
console.log(e.name); // "URIError"
console.log(e.stack); // このエラーのスタック
}
仕様書
| 仕様書 |
|---|
| ECMAScript® 2027 Language Specification> # sec-nativeerror-constructors> |