URIError
Baseline
広く利用可能
*
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2015年7月以降、すべてのブラウザーで利用可能です。
* この機能の一部は、対応レベルが異なる場合があります。
URIError オブジェクトは、グローバル URI 処理関数が間違った方法で使用された場合のエラーを表します。
URIError はシリアライズ可能オブジェクトであるため、structuredClone() で複製したり、ワーカー間で postMessage() を使用してコピーしたりすることができます。
URIError は Error のサブクラスです。
コンストラクター
URIError()-
新しい
URIErrorオブジェクトを生成します。
インスタンスプロパティ
親である Error から継承したプロパティもあります。
これらのプロパティは URIError.prototype で定義されており、すべての URIError インスタンスで共有されます。
URIError.prototype.constructor-
このインスタンスオブジェクトを作成したコンストラクター関数です。
URIErrorのインスタンスでは、初期値はURIErrorコンストラクターです。 URIError.prototype.name-
エラーの種類の名前を表します。
URIError.prototype.nameの場合、初期値は"URIError"です。
インスタンスメソッド
親である Error から継承したメソッドがあります。
例
>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", "someFile.js", 10);
} 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-native-error-types-used-in-this-standard-urierror> |