-
Notifications
You must be signed in to change notification settings - Fork 1
/
throw.xml
65 lines (64 loc) · 1.65 KB
/
throw.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../../../template/operatorWrapper.xsl"?>
<statement name="throw" xmlns="http://www.jsman.net/xsd/manual"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jsman.net/xsd/manual ../../../schema/jsman-manual.xsd">
<lead>
<p>throw – Throw an exception.</p>
</lead>
<description>
<p>throw <params/></p>
</description>
<parameters>
<parameter name="expression" optional="false"></parameter>
</parameters>
<examples>
<example>
<heading>throw example</heading>
<code>
try {
throw 42;
console.log('Never executed.');
}
catch (e) {
console.log(e); // 42
}
</code>
</example>
<example>
<heading>throw example</heading>
<code>
try {
throw new Error(42);
console.log('Never executed.');
}
catch (e) {
console.log(e); // Error: 42(…)
console.log(e.message); // 42
console.log(e.name); // Error
}
</code>
</example>
<example>
<heading>throw example</heading>
<code>
function myException (code, message) {
this.name = 'myException';
this.code = code;
this.message = message;
}
try {
throw new myException(42, 'Custom exception.');
console.log('Never executed.');
}
catch (e) {
console.log(e.code); // 42
console.log(e.message); // Custom exception.
console.log(e.name); // myException
}
</code>
</example>
</examples>
<external>
<mdn href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/throw">throw statement</mdn>
</external>
</statement>