SVGException

DOMException インターフェイス (DOM)

[112] DOMException は、 DOM API で用いられる例外です。

[113] DOM API は、 JavaScript 本体の Error のいずれかか、 または DOMException例外として投げることがあります。

[114] かつて W3C DOM 時代には他の種類の例外も定義されていたことがありましたが、 既に廃止され、 両者に統合されました。

目次

  1. 仕様書
  2. 意味
  3. コンストラクター
  4. 状態
  5. メンバー
  6. code 属性
  7. 歴史
    1. W3C DOM 時代
      1. 例外符号
    2. WHATWG でのメンテナンス
    3. DOM Standard
    4. Web IDL 特別なオブジェクト時代
      1. 演算
      2. 大域オブジェクト
      3. 構築子オブジェクト
      4. プロトタイプオブジェクト
    5. Web IDL 通常オブジェクト時代

仕様書#

意味#

[25] Web IDLの型 DOMException は、 例外のうち DOMException であるものを表します >>20

[27] 型名は、 DOMException です >>26

コンストラクター#

[69] DOMException コンストラクターは、 次のようにしなければなりません >>34

  1. [70] メッセージを、第1引数を DOMString と解釈した結果に設定します。 既定値空文字列とします。
  2. [72] 名前を、第2引数を DOMString と解釈した結果に設定します。 既定値Error とします。
  3. [73] 例外を、新しい DOMException に設定します。
    [74] DOMException
    名前
    名前
    メッセージ
    メッセージ
  4. [75] 例外を返します。

状態#

[66] DOMException は、プラットフォームオブジェクトの状態に加えて、 次の状態を持ちます。

名前
例外としての名前 (Errorname に相当)。
メッセージ
例外の説明文 (Errormessage に相当)。

[68] DOMExceptionインターフェイスプロトタイプオブジェクトPrototype は、 %ErrorPrototype% でなければなりません >>34

メンバー#

[42] DOMException インターフェイスには、 次のメンバーがあります。

[67] DOMExceptionインターフェイスメンバー
[45] DOMException はほとんど JavaScript Error と同じようであるよう定義されており、実装が非標準の特性Error に追加する場合は、 DOMException にも晒すべきです。 >>34

code 属性#

[109] DOMException には例外欄 code があります。データ型unsigned short です >>106

[110] W3C DOM 時代から存在していたエラーには、エラー名に対応する code 値が定義されています >>104DOMException投げられた時、エラー名に対応する値があればそれが code に設定され、なければ 0 となります >>104

[111] W3C DOM 時代には、例外の種別を識別する唯一の方法が code でした。しかし数値の定数によって列挙型を表す方法は JavaScript 的ではなく (Java 流であり)、 DOM4 時代以後新たなエラーには code を割り当てず、エラー名文字列による識別が導入されています。

[134] GeolocationPositionError インターフェイスにも、 同じような code IDL属性があります。 >>133 設定される値は unsigned short>>133DOMException とは別系統です。 実例はGeolocationPositionError

歴史#

W3C DOM 時代#

[64] DOMExceptionDOM1 で導入されました。当時の W3C DOMOMG IDL を用いており、その exception として定義されていました。 Java束縛では Java例外に、 JavaScript束縛では JavaScriptの の例外に対応付けられることが想定されていました。

[1] DOM では、処理を行えない時に例外 (exception) が発生します。 特に DOM 全般で発生し得る例外や DOM Core Module・XML Module で使われる例外が DOMException です。

ちなみに、処理が行えない時というのは (1) 論理的理由から行えない時、 (2) データが失われた時 (3) 実装が不安定な時などです。 通常索引に範囲外の値が指定された場合などは例外ではなく null 値が返される程度で済まされます。 また、束縛によっては例外という概念がないので、返し値などで伝達されることになります。

[4] DOMException は DOM Core Module の一部です。 すべての DOM 実装が完全に実装しなければなりません。

[5] 仕様書:

[6] DOMException の例外の種類は定義群 ExceptionCode の定数で識別されます。

[7]

名前出典
codeunsigned short[DOM 1,2,3]

[8] DOMSTRING_SIZE_ERR はほとんどすべての DOMString 型メソッド・属性で発生し得ると思うのですが、 仕様書には一部のメソッド・属性にしか書いてありません。 例えば Node.localName 取得時に起こっても不思議はないのですが、 実際にはそんな猛烈な長さの名前など到底使われそうにも無いからなのか、例外が発生し得るとは書いてありません。 (名無しさん)

[9] IRC logs: freenode / #whatwg / 20080811 (2008-08-14 19:22:43 +09:00 版) http://krijnhoetmer.nl/irc-logs/whatwg/20080811

例外符号#

[11]

INVALID_EXPRESSION_ERR51DOM XPath (XPathException)
TYPE_ERR52DOM XPath (XPathException)
NO_SCHEMA_AVAILABLE_ERR71DOM妥当性検証 (ExceptionVal)
PARSE_ERR81DOM LS (LSException)
SERIALIZE_ERR82DOM LS (LSException)

[53] DOM3 で導入された例外 LSException, ExceptionVal, XPathException符号DOMException とかぶらないようになっていますが、 DOM2 で導入されたもの (EventException, RangeException) はかぶっています。

[83] 完成しなかった DOM AS も古い時期で放棄されたためか DOMException とかぶっています。

[132] 時代的に DOM3 より少し後に当たる GeolicationPositionError例外同様のインターフェイスになっていますが、 符号はかぶっています。 そのためか、 DOMException 以外の例外が廃止された後も GeolocationPositionError は存続しています。

[84] なんで60番台は使われていないのでしょう。

[94] 定義群 ExceptionCode は、 DOMException例外の種類を表す定数群です。

仕様書:

[95]

定数名定数値説明水準
DOMSTRING_SIZE_ERR2文の指定された範囲が DOMString に一致しません。DOM 1,2,3
HIERARCHY_REQUEST_ERR3Node がどこか所属しない場所に挿入しようとしています。DOM 1,2,3
INDEX_SIZE_ERR1索引または寸法が負か、認められる値を超えています。DOM 1,2,3
INUSE_ATTRIBUTE_ERR10すでにどこかで使われている属性を追加しようとしています。DOM 1,2,3
INVALID_ACCESS_ERR15引数または演算に当該物体は対応していません。DOM 2,3
INVALID_CHARACTER_ERR5不当または不法な文字が (例えば XML の名前中で) 指定されています。DOM 1,2,3
INVALID_MODIFICATION_ERR13当該物体の型を修正しようとしています。DOM 2,3
INVALID_STATE_ERR11使用可能でないか、既に使用不能な物体を使おうとしています。DOM 2,3
NAMESPACE_ERR14名前空間に関して不正な方法で物体を作成または変更しようとしています。DOM 2,3
NOT_FOUND_ERR8Node を存在しない文脈で参照しようとしています。DOM 1,2,3
NOT_SUPPORTED_ERR9要求された型の物体または演算に実装は対応していません。DOM 1,2,3
NO_DATA_ALLOWED_ERR6データに対応していない Node でデータを指定しています。DOM 1,2,3
NO_MODIFICATION_ALLOWED_ERR7修正が認められていない物体を修正しようとしています。DOM 1,2,3
SYNTAX_ERR12不当または不法な文字列が指定されています。DOM 2,3
TYPE_MISMATCH_ERR17物体の型が物体に関連付けられた引数の型として期待されるものと非互換です。DOM 3
VALIDATION_ERR16Node部分妥当性について不当となる操作をしようとしています。DOM 3
WRONG_DOCUMENT_ERR4Node が作られたのと違う文書で使われています。DOM 1,2,3
(その他)(W3C が将来の使用のために予約)DOM 1 SE,2,3

WHATWG でのメンテナンス#

[22] W3C DOMDOM3 を最後に放置されました。

[21] DOMException への追加の例外符号は、 HTML Standard で規定された他、 WHATWG Wiki のページに一覧が掲載されていて、 他の仕様で規定された追加分もまとめられていました。

[142] Exception Codes - WHATWG Wiki (2007-09-25 18:06:18 +09:00 版) http://wiki.whatwg.org/wiki/Exception_Codes

[10] Exception Codes - WHATWG Wiki ( 版) http://wiki.whatwg.org/wiki/Exception_Codes

[85] IRC logs: freenode / #whatwg / 20100809 ( 版) http://krijnhoetmer.nl/irc-logs/whatwg/20100809#l-521

[86] Web Applications 1.0 r5311 Make the structured clone algorithm using DATA_CLONE_ERR rather than NOT_SUPPORTED_ERR, for sicking.Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id=10069 ( ( 版)) http://html5.org/tools/web-apps-tracker?from=5310&to=5311

[87] Web Applications 1.0 r5416 Fix potential clash with File API. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=5415&to=5416

[88] IRC logs: freenode / #whatwg / 20100913 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20100913

[89] Web Applications 1.0 r5773 File API no longer uses DOMException ( ( 版)) http://html5.org/tools/web-apps-tracker?from=5772&to=5773

[90] IRC logs: freenode / #whatwg / 20110427 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20110427

[91] Bug 10623 – Simplify Web IDL exceptions ( ( 版)) http://www.w3.org/Bugs/Public/show_bug.cgi?id=10623

[92] IRC logs: freenode / #whatwg / 20110415 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20110415#l-993

[93] 743888 – Replace SVGException and XPathException with DOMException ( ( 版)) https://bugzilla.mozilla.org/show_bug.cgi?id=743888

[96] Chromename 属性INUSE_ATTRIBUTE_ERR のような定数名を設定します。

DOM Standard#

[23] W3C DOM にかわる WHATWG DOM Standard の標準化により、 すべてのエラーコードが再び一箇所で規定されるようになりました。 またその後の WHATWGW3C WebApps WGpublic-script-coord などの議論で、 Java 風の整数 + 定数のエラーコードを新規追加せず文字列名によってエラーを区別することや、独自の例外インターフェイスに替えて専ら DOMException を使うことが決まりました。

[97] Bug 101606 – DOMException name is incorrect ( ( 版)) https://bugs.webkit.org/show_bug.cgi?id=101606

[98] DOM Standard は新しい name を廃止されていない例外の種類に対してしか定義していませんが、 >>97 は廃止されたものも含めて新しいスタイルの name を実装しています。

[99] [whatwg] DOMError not constructable ( ( 版)) http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2013-February/038857.html

[100] ES Discuss ( ( 版)) http://esdiscuss.org/topic/creating-your-own-errors

[101] IRC logs: freenode / #whatwg / 20140401 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20140401

[102] Inform the world DOMException and DOMError are moving out · db88f3a · whatwg/dom ( ( 版)) https://github.com/whatwg/dom/commit/db88f3a50274590a52aaabba97cacfaa84853933

[103] Improve warnings in Errors section. · 3287ee4 · whatwg/dom ( ( 版)) https://github.com/whatwg/dom/commit/3287ee475b41b8ee373affaab368422e500ef3c3

[115] Turns out nobody filed bugs for all these error names. And since IDL is ... · 26a792e · whatwg/dom ( ( 版)) https://github.com/whatwg/dom/commit/26a792e2375134ca6283797025ed7a9d448220b2

Web IDL 特別なオブジェクト時代#

[24] DOMException 以外の例外を定義する必要が無くなったことから、 Web IDLexception 機能は削除されることとなりました。 DOMException の規定も DOM Standard から Web IDL へと移動しました。また、 JavaScript のエラー (単純例外) が利用できる場合はそちらを使う方が好ましいと考えられるようになり、 そのための規定も Web IDL で整備されています。

[116] Bug 23367 – Move exceptions into IDL ( ( 版)) https://www.w3.org/Bugs/Public/show_bug.cgi?id=23367

[117] DOMException is in IDL. DOMError removed. https://www.w3.org/Bugs/Public... · 7fe5736 · whatwg/dom ( ( 版)) https://github.com/whatwg/dom/commit/7fe5736d3ed2717d71a3d2627b07dee97e10ef05

[118] DOMException is in IDL. DOMError removed. https://www.w3.org/Bugs/Public... · 7fe5736 · whatwg/dom ( ( 版)) https://github.com/whatwg/dom/commit/7fe5736d3ed2717d71a3d2627b07dee97e10ef05

[119] Removed IDL exceptions, baked in DOMException, and added Error and DOMEx... · 50e172e · heycam/webidl ( ( 版)) https://github.com/heycam/webidl/commit/50e172ec079db073c3724c9beac1b576fb5dbc47

[18] Web Applications 1.0 r8887 fix exception references to match where things are now defined ( 版) https://html5.org/r/8887

[19] Bug 21740 – Guidance on DOMError and promises ( ( 版)) https://www.w3.org/Bugs/Public/show_bug.cgi?id=21740

[46] Merge pull request #22 from domenic/domexception-name · heycam/webidl@370fc8c ( 版) https://github.com/heycam/webidl/commit/370fc8c6e9db2aaf017b266b4b00a36aeedffaf9

[49] Merge pull request #472 from w3c/errorManagement · w3c/webrtc-pc@2774184 ( 版) https://github.com/w3c/webrtc-pc/commit/27741843a39b5300fced351be124f54d92dc1970

[50] Merge branch 'not-allowed-error' of git://github.com/mounirlamouri/we… · heycam/webidl@b460b6a ( 版) https://github.com/heycam/webidl/commit/b460b6a875fdfe7dc34f40d1eb57ed1ae8d8f5f5

[54] 743888 – Replace SVGException and XPathException with DOMException ( ()) https://bugzilla.mozilla.org/show_bug.cgi?id=743888

[55] 21740 – Guidance on DOMError and promises ( ()) https://www.w3.org/Bugs/Public/show_bug.cgi?id=21740

[56] 27732 – DOMException lost some constants. () https://www.w3.org/Bugs/Public/show_bug.cgi?id=27732

[57] Deprecate InvalidAccessError. (#246) (tobie著, ) https://github.com/heycam/webidl/commit/671706df92e2cece78d747c1db73fbf863e7ec86

[58] Add missing legacy error names. (#251) (tobie著, ) https://github.com/heycam/webidl/commit/c50ffc45f6e8c19262aed531bbe6b047101c3b06

[59] Exception cleanup (#250) (tobie著, ) https://github.com/heycam/webidl/commit/c2d602f15a60765832e52b9c4a62f7ae76b2950c

[60] Editorial: merge deprecated DOMExceptions back in main table (#285) (tobie著, ) https://github.com/heycam/webidl/commit/5c6c00b2ae700caee37ad00450011c2e812b1624

[61] Use DOMException rather than DOMError. (mkruisselbrink著, ) https://github.com/w3c/FileAPI/commit/98f4af667dee7ab88495df90759ed0c225b52672

[62] Clarify that exceptions are always thrown in the current Realm (#300) (domenic著, ) https://github.com/heycam/webidl/commit/20b87a7d44d94a153762a5c1c587779767afbfe6

[43] DOMException は、 DOMExceptionプロトタイプオブジェクトから継承するプラットフォームオブジェクトによって表されます >>34

[44] DOMException は次の状態を持ちます。

大域環境
>>34
Prototype
大域環境DOMExceptionプロトタイプオブジェクト >>34
クラス文字列
DOMException >>34

演算#

[29] JavaScript 値から DOMException Web IDL値への変換は、 次のように定義されています >>28

  1. [30] 指定された値が Object でないか、 指定された値が DOMException を表すプラットフォームオブジェクトでないなら、 TypeError投げ、停止します。
  2. [31] 指定された値と同じオブジェクトを指す Web IDL DOMException 値を返します。

[32] Web IDL 値から JavaScript値への変換は、 次のように定義されています >>28

  1. [33] 指定された値と同じオブジェクトを指す JavaScript Object 値を返します。

大域オブジェクト#

[35] JavaScript大域オブジェクトは、次の特性を持たなければなりません >>34

JavaScript特性
名前
DOMException
DOMException構築子オブジェクト
Writable
Enumerable
Configurable

構築子オブジェクト#

[36] DOMException構築子オブジェクト (DOMException constructor object) は、 次のような関数オブジェクトでなければなりません >>34

関数オブジェクト
Prototype
%Error%
prototype 特性
JavaScript特性
名前
prototype
DOMExceptionプロトタイプオブジェクト
Writable
Enumerable
Configurable

[47] DOMException構築子オブジェクトは、初期オブジェクトです。

[37] 更に、エラー名表の各定数について、次のような特性がなければなりません >>34

JavaScript特性
名前
エラー名表定数
エラー名表定数
Writable
Enumerable
Configurable

[39] 構築子としての DOMException構築子オブジェクトは、 実行すると、新しい DOMException オブジェクトを作成し、返します。 第1引数はメッセージ (例外)と解釈されます。第2引数は省略可能で、 指定されたら name として使われるとともに、 code の設定に使われます。

[38] この関数は、次のように処理します >>34

  1. F を、活性関数オブジェクトに設定します。
  2. newTarget を、 NewTarget (それが undefined の場合は、 F) に設定します。
  3. FgetPrototypeOf を実行します。 super を、その実行結果に設定します。例外が投げられたなら伝播し、停止します。
  4. superIsConstructor を適用した結果がなら、 TypeError を投げ、停止します。
  5. Construct を実行します。 super、第1引数で構成されるリスト、 newTarget引数として渡します。 O を、結果に設定します。
  6. O大域環境を、本関数大域環境に設定します。
  7. 第2引数が undefined 以外なら、
    1. name を、第2引数の ToString とします。
    2. DefinePropertyOrThrowO特性を次の通り設定します。 例外が投げられたなら伝播し、停止します。
      JavaScript特性
      名前
      name
      Value
      name
      Writable
      Enumerable
      Configurable
    3. DefinePropertyOrThrowO特性を次の通り設定します。 例外が投げられたなら伝播し、停止します。
      JavaScript特性
      名前
      code
      Value
      エラー名表name に相当する符号があればその値、なければ 0
      Writable
      Enumerable
      Configurable
  8. O を返します。

プロトタイプオブジェクト#

[40] DOMExceptionプロトタイプオブジェクト (DOMException prototype object) は、 次のようなオブジェクトでなければなりません >>34

JavaScriptオブジェクト
Prototype
%ErrorPrototype%
クラス文字列
DOMExceptionPrototype
constructor 特性
JavaScript特性
名前
constructor
Value
DOMException構築子オブジェクト
Writable
Enumerable
Configurable

[48] DOMExceptionプロトタイプオブジェクトは、初期オブジェクトです。

[41] 更に、エラー名表の各定数について、次のような特性がなければなりません >>34

JavaScript特性
名前
エラー名表定数
Value
エラー名表定数
Writable
Enumerable
Configurable

Web IDL 通常オブジェクト時代#

[65] 2017年、実装状況に合わせる形で、 Web IDL 仕様書の本文で規定される JavaScriptオブジェクトという形から、 Web IDL インターフェイスへと変更されました。

[63] Re-align DOMException objects with what is implemented (#378) (domenic著, ) https://github.com/heycam/webidl/commit/5c8eb310ef7a6bcb3c4813e9791212ee1624f2d3

[76] DOMException function definition makes no sense · Issue #55 · heycam/webidl () https://github.com/heycam/webidl/issues/55

[77] DOMException function definition makes no sense · Issue #55 · heycam/webidl () https://github.com/heycam/webidl/issues/55

[78] Re-align DOMException objects with what is implemented by domenic · Pull Request #378 · heycam/webidl () https://github.com/heycam/webidl/pull/378

[79] Remove DOMException terminal from the grammar (domenic著, ) https://github.com/heycam/webidl/commit/b0855366cc78001725b26ec5c9096c9d3a101f62

[80] Remove DOMException terminal from the grammar by domenic · Pull Request #385 · heycam/webidl () https://github.com/heycam/webidl/pull/385

[105] Use `DOMException` instead of `Error` in `SensorErrorEvent` (pozdnyakov著, ) https://github.com/w3c/sensors/commit/810d1a9b646585d954f4798e227cbf218a2ff9eb

[107] Editorial: use "exception name" DOMException notation (tobie著, ) https://github.com/whatwg/dom/commit/9d83a6406bc57a7deeb5c0831c388bae752f2e5e

[108] Editorial: use "exception name" DOMException notation by tobie · Pull Request #518 · whatwg/dom () https://github.com/whatwg/dom/pull/518

[120] Editorial: cleanup exception terminology (annevk著, ) https://github.com/whatwg/xhr/commit/4b7915e396bbdf3ae39495740c581556e4020eaf

[121] Editorial: use "{{ExceptionType!!exception}}" {{DOMException}} throughout · Issue #173 · whatwg/xhr () https://github.com/whatwg/xhr/issues/173

[122] Editorial: cleanup exception terminology by annevk · Pull Request #195 · whatwg/xhr () https://github.com/whatwg/xhr/pull/195

[123] Clarify note about DOMException (Ms2ger著, ) https://github.com/heycam/webidl/commit/4ef350963f4b9ef5246b2bc420d8bab8ed7b6282

[124] Remove the Error IDL type by Ms2ger · Pull Request #728 · heycam/webidl () https://github.com/heycam/webidl/pull/728

[125] Remove DOMException conversion section (Ms2ger著, ) https://github.com/heycam/webidl/commit/ff88ac4876d747a2ae3ad553f42525927bde4605

[126] Remove the Error IDL type by Ms2ger · Pull Request #728 · heycam/webidl () https://github.com/heycam/webidl/pull/728

[127] Remove the 'exception types' definition (Ms2ger著, ) https://github.com/heycam/webidl/commit/faaee577b0c0c03338b139754835ac999de507be

[128] Use new syntax for DOMException. (#780) (Ms2ger著, ) https://github.com/heycam/webidl/commit/21ffd9bd979bbebc99d1b7ed28c4f56b7c02b018

[129] Use new syntax for DOMException. by Ms2ger · Pull Request #780 · heycam/webidl () https://github.com/heycam/webidl/pull/780

[130] Revert "Use new syntax for DOMException. (#780)" (bzbarsky著, ) https://github.com/heycam/webidl/commit/182b487c128bce00e62431f19458c15fe91e9738

[131] Revert "Use new syntax for DOMException." by bzbarsky · Pull Request #781 · heycam/webidl () https://github.com/heycam/webidl/pull/781

[135] Remove use of [Constructor] extended attribute (clelland著, ) https://github.com/heycam/webidl/commit/9e514c9dcfb09919af971931409aa075451804a5

[136] Remove use of [Constructor] extended attribute by clelland · Pull Request #798 · heycam/webidl () https://github.com/heycam/webidl/pull/798

[137] Copy the DOM XPath interfaces from the WHATWG wiki by foolip · Pull Request #763 · whatwg/dom () https://github.com/whatwg/dom/pull/763

[138] Mark DOMException as serializable by yutakahirano · Pull Request #732 · heycam/webidl () https://github.com/heycam/webidl/pull/732

[139] Make DOMException serializable (yutakahirano, , ) https://github.com/heycam/webidl/commit/f23ef42038a1d6af6ba19806c8246673711ee7ca

[140] Define serialization and deserialization steps for DOMException · Issue #729 · heycam/webidl () https://github.com/heycam/webidl/issues/729

[141] Mark DOMException as serializable by yutakahirano · Pull Request #732 · heycam/webidl () https://github.com/heycam/webidl/pull/732