-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy patherror.jsdoc
More file actions
129 lines (100 loc) · 2.27 KB
/
Copy patherror.jsdoc
File metadata and controls
129 lines (100 loc) · 2.27 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
Error : Object
An object thrown when an error occurs.
There are several specific constructor functions for different types of
error conditions:
**EvalError**,
**RangeError**,
**ReferenceError**,
**SyntaxError**,
**TypeError**,
**URIError**,
**NativeError**.
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.11
----
Error(message : String) : Error
Same as %%#new_Error_String|**new Error(message)**%%.
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.11.1.1
----
Error(message : String, options : Object) : Error
Same as %%#new_Error_String_Object|**new Error(message, options)**%%.
Spec:
https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-error-constructor
----
new Error(message : String) : Error
Creates a new **Error** with the specified **message** that describes the error.
<example>
var divide = function(x, y) {
if (y === 0) {
throw new Error('divide by zero');
}
return x / y;
};
try {
console.log(divide(10, 0));
}
catch (error) {
console.log(error.name);
console.log(error.message);
}
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.11.2.1
----
new Error(message : String, options : { cause : Error }) : Error
Creates a new **Error** with the specified **message** that describes the error and
original **cause** of the error.
<example>
var validateNumber = function(x) {
if (typeof x !== 'number') {
throw Error(x + ' is not a number');
}
return x;
};
var multiply = function(x, y) {
try {
return validateNumber(x) * validateNumber(y);
}
catch(e) {
throw Error('Unable to multiply', { cause: e });
}
};
try {
console.log(multiply(3, 'abc'));
}
catch (error) {
console.log(error);
console.log('Cause:', error.cause);
}
</example>
Spec:
https://tc39.es/ecma262/multipage/fundamental-objects.html#sec-error-constructor
Version:
ECMAScript 2022
----
prototype.message : String
A human readable message that describes the error.
<example>
try {
foo;
}
catch (error) {
console.log(error.message);
}
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.11.4.3
----
prototype.name : String
The type of error.
<example>
try {
foo;
}
catch (error) {
console.log(error.name);
}
</example>
Spec:
http://www.ecma-international.org/ecma-262/5.1/#sec-15.11.4.2