* 仕様書

[REFS[
- [26] '''[CITE[ECMAScript® 2018 Language Specification]] ([TIME[2017-07-13 07:36:55 +09:00]]) <https://tc39.github.io/ecma262/#sec-error-objects>'''
- [9] [CITE[Web IDL (Second Edition)]] ([TIME[2015-05-27 01:29:33 +09:00]] 版) <http://heycam.github.io/webidl/#dfn-simple-exception>
- [15] [CITE[Web IDL (Second Edition)]] ([TIME[2015-05-27 01:29:33 +09:00]] 版) <http://heycam.github.io/webidl/#idl-Error>
- [17] [CITE[Web IDL (Second Edition)]] ([TIME[2015-05-27 01:29:33 +09:00]] 版) <http://heycam.github.io/webidl/#es-Error>
]REFS]

* 意味

[13] [[Web IDL]] の[[型]] [CODE(IDL)@en[[[Error]]]] は、
[[Web IDL]] [[例外]]を表します [SRC[>>9]]。

;; [14] [CODE(IDL)@en[[[DOMException]]]] も含まれます。
[CODE(IDL)@en[[[SyntaxError]]]] が含まれるのかは謎です。

[16] [[型名]]は、 [CODE(IDL)@en[[[Error]]]] です [SRC[>>15]]。

* サブクラス

[FIG(short list)[
- [CODE(JS)@en[[[EvalError]]]]
- [CODE(JS)@en[[[RangeError]]]]
- [CODE(JS)@en[[[ReferenceError]]]]
- [CODE(JS)@en[[[SyntaxError]]]]
- [CODE(JS)@en[[[TypeError]]]]
- [CODE(JS)@en[[[URIError]]]]
- [CODE(DOMi)@en[[[DOMException]]]]
]FIG]

* 単純例外

[10] [[Web IDL]] は、[[例外]]のうち次のものを[DFN[[RUBYB[[[単純例外]]]@en[simple exception]]]]と呼んでいます [SRC[>>9]]。
[FIG(short list)[
- [CODE(IDL)@en[[[EvalError]]]]
- [CODE(IDL)@en[[[RangeError]]]]
- [CODE(IDL)@en[[[ReferenceError]]]]
- [CODE(IDL)@en[[[TypeError]]]]
- [CODE(IDL)@en[[[URIError]]]]
]FIG]

[11] これらは [[JavaScript]] の [CODE(JS)@en[[[Error]]]] の[[部分クラス]]に相当します。
ただし [CODE(JS)@en[[[SyntaxError]]]] は[[JavaScript]]の[[構文解析]]のみに使うとして、
[CODE(JS)@en[Error]] 自体は[[著者]]が使うものであるとして、
除外されています。 [SRC[>>9]]

;; [12] 実際には [[DOM]] でも、 [[Worker]] の処理で [CODE(JS)@en[[[SyntaxError]]]]
を使っています (が [[JavaScript]] の[[構文解析]]に関するエラーを表すものです)。

* メンバー

[FIG(short list)[ [27] [CODE(JS)@en[Error]] の[[メンバー]]
- [CODE(JS)@en[name]]
- [CODE(JS)@en[message]]
- [CODE(JS)@en[toString]]
]FIG]

* 演算

[18] [[JavaScript]] 値から [CODE(IDL)@en[[[Error]]]] [[Web IDL値への変換]]は、
次のように定義されています [SRC[>>17]]。
[FIG(steps)[
= [19] 指定された値が [CODE(JS)@en[[[Object]]]] でないか、 
[CODE[[[ErrorData]]]] [[内部スロット]]を持たないなら、
[CODE(JS)@en[[[TypeError]]]] を[[投げ]]、停止します。
= [20] 指定された値と同じオブジェクトを指す [[Web IDL]] [CODE(IDL)@en[[[Error]]]] 値を返します。
]FIG]

[21] [[Web IDL]] 値から [[JavaScript値への変換]]は、
次のように定義されています [SRC[>>17]]。
[FIG(steps)[
= [22] 指定された値と同じオブジェクトを指す [[JavaScript]] [CODE(JS)@en[[[Error]]]]
値を返します。
]FIG]

* 歴史

- [4] '''[CITE@en-GB[ECMAScript Language Specification ECMA-262 6th Edition – DRAFT]] ([TIME[2014-08-27 17:42:43 +09:00]] 版) <http://people.mozilla.org/~jorendorff/es6-draft.html#sec-error-objects>'''

[REFS[
- [1] [CITE@en-US[Error - JavaScript | MDN]]
( ([TIME[2012-10-29 12:26:49 +09:00]] 版))
<https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/Error>
- [2] [CITE@en-us[Error Object (JavaScript)]]
( ([TIME[2012-11-25 02:45:06 +09:00]] 版))
<http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx>
- [3] [CITE@en-us[Error Object]]
( ([TIME[2012-11-25 02:44:09 +09:00]] 版))
<http://msdn.microsoft.com/en-us/library/vstudio/t9zk6eay(v=vs.100).aspx>
]REFS]

[5] [CITE[JavaScriptでカスラムエラーをどう作るか - rikubaの日記]]
( ([TIME[2014-04-10 02:13:58 +09:00]] 版))
<http://d.hatena.ne.jp/rikuba/20140409/1397031752>

[6] [CITE@en[Removed IDL exceptions, baked in DOMException, and added Error and DOMEx... · 50e172e · heycam/webidl]]
( ([TIME[2014-10-10 07:55:16 +09:00]] 版))
<https://github.com/heycam/webidl/commit/50e172ec079db073c3724c9beac1b576fb5dbc47>

[7] [CITE@en[DOMException is in IDL. DOMError removed. https://www.w3.org/Bugs/Public... · 7fe5736 · whatwg/dom]]
( ([TIME[2014-10-10 07:56:50 +09:00]] 版))
<https://github.com/whatwg/dom/commit/7fe5736d3ed2717d71a3d2627b07dee97e10ef05>

[8] [CITE@en[Removed IDL exceptions, baked in DOMException, and added Error and DOMEx... · 50e172e · heycam/webidl]]
( ([TIME[2014-10-10 07:57:10 +09:00]] 版))
<https://github.com/heycam/webidl/commit/50e172ec079db073c3724c9beac1b576fb5dbc47>

[23] [CITE@en[Write structured clone algorithm in terms of ECMAScript · whatwg/html@bfb960c]]
([TIME[2016-03-02 16:48:55 +09:00]] 版)
<https://github.com/whatwg/html/commit/bfb960c938580c95e77365e614218b952f96375b>

[24] [CITE@en[Exception cleanup (#250)]]
([[tobie]]著, [TIME[2016-12-13 18:46:16 +09:00]])
<https://github.com/heycam/webidl/commit/c2d602f15a60765832e52b9c4a62f7ae76b2950c>

[25] [CITE@en[Clarify that exceptions are always thrown in the current Realm (#300)]]
([[domenic]]著, [TIME[2017-02-07 15:56:01 +09:00]])
<https://github.com/heycam/webidl/commit/20b87a7d44d94a153762a5c1c587779767afbfe6>

[28] [CITE@en[DOMException function definition makes no sense · Issue #55 · heycam/webidl]]
([TIME[2017-08-21 22:39:41 +09:00]])
<https://github.com/heycam/webidl/issues/55>

[29] [CITE@en[tc39/proposal-error-stacks: ECMAScript Proposal, specs, and reference implementation for Error.prototype.stack / System.getStack]]
([TIME[2017-08-21 22:51:33 +09:00]])
<https://github.com/tc39/proposal-error-stacks>

[30] [CITE@en[Use `DOMException` instead of `Error` in `SensorErrorEvent`]]
([[pozdnyakov]]著, [TIME[2017-10-11 22:42:19 +09:00]])
<https://github.com/w3c/sensors/commit/810d1a9b646585d954f4798e227cbf218a2ff9eb>

[31] [CITE@en[Remove the Error IDL type]]
([[Ms2ger]]著, [TIME[2019-05-17 22:52:31 +09:00]])
<https://github.com/heycam/webidl/commit/ad03037c82890e7ac496b96922552f465c45c0a7>

[32] [CITE@en[Remove the Error IDL type]]
([[Ms2ger]]著, [TIME[2019-05-17 22:52:31 +09:00]])
<https://github.com/heycam/webidl/commit/ad03037c82890e7ac496b96922552f465c45c0a7>

[33] [CITE@en[Remove the Error IDL type by Ms2ger · Pull Request #728 · heycam/webidl]]
([TIME[2020-01-12 14:12:28 +09:00]])
<https://github.com/heycam/webidl/pull/728>

[34] [CITE@en[Remove the 'exception types' definition]]
([[Ms2ger]]著, [TIME[2019-05-17 23:21:01 +09:00]])
<https://github.com/heycam/webidl/commit/faaee577b0c0c03338b139754835ac999de507be>

[35] [CITE[javascript - checking for typeof error in JS - Stack Overflow]]
([TIME[2020-03-25 13:46:55 +09:00]])
<https://stackoverflow.com/questions/30469261/checking-for-typeof-error-in-js>

[36] [CITE@en[Define serialization and deserialization steps for errors]]
([[yutakahirano]], [TIME[2019-07-04 00:03:13 +09:00]], [TIME[2021-04-12T06:50:42.000Z]])
<https://github.com/whatwg/html/commit/af9f08794fc97d442f8a25c5eeac9f9f70aea498>

[37] [CITE@en[Allow structured cloning of native error types · Issue #4268 · whatwg/html]]
([TIME[2021-04-12T06:52:02.000Z]])
<https://github.com/whatwg/html/issues/4268>

[38] [CITE@en[Structured cloning of errors · Issue #165 · mozilla/standards-positions]]
([TIME[2021-04-12T06:58:20.000Z]])
<https://github.com/mozilla/standards-positions/issues/165>

[39] [CITE@en[28389 – Allow error objects to be structured-clonable]]
([TIME[2019-04-02T04:48:11.000Z]], [TIME[2021-04-12T06:59:26.043Z]])
<https://www.w3.org/Bugs/Public/show_bug.cgi?id=28389>

[40] [CITE@en[Define serialization and deserialization steps for Error by yutakahirano · Pull Request #4665 · whatwg/html]]
([TIME[2021-04-12T07:02:33.000Z]])
<https://github.com/whatwg/html/pull/4665>

[41] [CITE@en[Normative: remove the '''[''''''['''ErrorData''']'''''']''' internal slot by domenic · Pull Request #438 · tc39/ecma262]]
([TIME[2021-04-12T07:03:43.000Z]])
<https://github.com/tc39/ecma262/pull/438>

[42] [CITE@en[Should we make native error types distinguishable? · Issue #1389 · tc39/ecma262]]
([TIME[2021-04-12T07:07:35.000Z]])
<https://github.com/tc39/ecma262/issues/1389>