Re: [whatwg/webidl] Allow DOMException subclasses to be used as exceptions (PR #1211)

@domenic commented on this pull request.



> @@ -5176,6 +5197,93 @@ over just using {{SyntaxError!!exception}} to refer to the {{DOMException}}. [[D
     </tbody>
 </table>
 
+<h4 id="idl-DOMException-derived-interfaces">{{DOMException}} derived interfaces</h4>
+
+When an exception needs to carry additional programmatically-introspectable information, beyond what
+can be provided with a {{DOMException}}'s [=DOMException/name=], specification authors can create an
+[=interface=] which [=interface/inherits=] from {{DOMException}}. Such interfaces need to follow
+certain rules, in order to have a predictable shape for developers. Specifically:
+
+*   The [=identifier=] of the [=interface=] must end with <code>Error</code>, and must not be any
+    of the names in the <a><code>DOMException</code> names table</a>.
+*   The [=interface=] must have a [=constructor operation=] which sets the instance's
+    [=DOMException/name=] to the interface's [=identifier=].
+*   Their [=constructor operation=] must take as its first parameter an [=optional argument|optional=]
+    {{DOMString}} named |message| defaulting to the empty string, and must set the instance's
+    [=DOMException/message=] to |message|.
+*   Their [=constructor operation=] should take as its second parameter a [=dictionary=] containing

Yeah. I'm not 100% sure, but I feel like being too prescriptive here is not necessary, since we don't know exactly what shape the additional information will come in.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/pull/1211#discussion_r1217599103
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/webidl/pull/1211/review/1461822619@github.com>

Received on Monday, 5 June 2023 06:48:29 UTC