Initial commit
[yaffs-website] / node_modules / nan / doc / errors.md
1 ## Errors
2
3 NAN includes helpers for creating, throwing and catching Errors as much of this functionality varies across the supported versions of V8 and must be abstracted.
4
5 Note that an Error object is simply a specialized form of `v8::Value`.
6
7 Also consult the V8 Embedders Guide section on [Exceptions](https://developers.google.com/v8/embed#exceptions) for more information.
8
9  - <a href="#api_nan_error"><b><code>Nan::Error()</code></b></a>
10  - <a href="#api_nan_range_error"><b><code>Nan::RangeError()</code></b></a>
11  - <a href="#api_nan_reference_error"><b><code>Nan::ReferenceError()</code></b></a>
12  - <a href="#api_nan_syntax_error"><b><code>Nan::SyntaxError()</code></b></a>
13  - <a href="#api_nan_type_error"><b><code>Nan::TypeError()</code></b></a>
14  - <a href="#api_nan_throw_error"><b><code>Nan::ThrowError()</code></b></a>
15  - <a href="#api_nan_throw_range_error"><b><code>Nan::ThrowRangeError()</code></b></a>
16  - <a href="#api_nan_throw_reference_error"><b><code>Nan::ThrowReferenceError()</code></b></a>
17  - <a href="#api_nan_throw_syntax_error"><b><code>Nan::ThrowSyntaxError()</code></b></a>
18  - <a href="#api_nan_throw_type_error"><b><code>Nan::ThrowTypeError()</code></b></a>
19  - <a href="#api_nan_fatal_exception"><b><code>Nan::FatalException()</code></b></a>
20  - <a href="#api_nan_errno_exception"><b><code>Nan::ErrnoException()</code></b></a>
21  - <a href="#api_nan_try_catch"><b><code>Nan::TryCatch</code></b></a>
22
23
24 <a name="api_nan_error"></a>
25 ### Nan::Error()
26
27 Create a new Error object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.0/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8.
28
29 Note that an Error object is simply a specialized form of `v8::Value`.
30
31 Signature:
32
33 ```c++
34 v8::Local<v8::Value> Nan::Error(const char *msg);
35 v8::Local<v8::Value> Nan::Error(v8::Local<v8::String> msg);
36 ```
37
38
39 <a name="api_nan_range_error"></a>
40 ### Nan::RangeError()
41
42 Create a new RangeError object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.0/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8.
43
44 Note that an RangeError object is simply a specialized form of `v8::Value`.
45
46 Signature:
47
48 ```c++
49 v8::Local<v8::Value> Nan::RangeError(const char *msg);
50 v8::Local<v8::Value> Nan::RangeError(v8::Local<v8::String> msg);
51 ```
52
53
54 <a name="api_nan_reference_error"></a>
55 ### Nan::ReferenceError()
56
57 Create a new ReferenceError object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.0/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8.
58
59 Note that an ReferenceError object is simply a specialized form of `v8::Value`.
60
61 Signature:
62
63 ```c++
64 v8::Local<v8::Value> Nan::ReferenceError(const char *msg);
65 v8::Local<v8::Value> Nan::ReferenceError(v8::Local<v8::String> msg);
66 ```
67
68
69 <a name="api_nan_syntax_error"></a>
70 ### Nan::SyntaxError()
71
72 Create a new SyntaxError object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.0/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8.
73
74 Note that an SyntaxError object is simply a specialized form of `v8::Value`.
75
76 Signature:
77
78 ```c++
79 v8::Local<v8::Value> Nan::SyntaxError(const char *msg);
80 v8::Local<v8::Value> Nan::SyntaxError(v8::Local<v8::String> msg);
81 ```
82
83
84 <a name="api_nan_type_error"></a>
85 ### Nan::TypeError()
86
87 Create a new TypeError object using the [v8::Exception](https://v8docs.nodesource.com/io.js-3.0/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8.
88
89 Note that an TypeError object is simply a specialized form of `v8::Value`.
90
91 Signature:
92
93 ```c++
94 v8::Local<v8::Value> Nan::TypeError(const char *msg);
95 v8::Local<v8::Value> Nan::TypeError(v8::Local<v8::String> msg);
96 ```
97
98
99 <a name="api_nan_throw_error"></a>
100 ### Nan::ThrowError()
101
102 Throw an Error object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new Error object will be created.
103
104 Signature:
105
106 ```c++
107 void Nan::ThrowError(const char *msg);
108 void Nan::ThrowError(v8::Local<v8::String> msg);
109 void Nan::ThrowError(v8::Local<v8::Value> error);
110 ```
111
112
113 <a name="api_nan_throw_range_error"></a>
114 ### Nan::ThrowRangeError()
115
116 Throw an RangeError object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new RangeError object will be created.
117
118 Signature:
119
120 ```c++
121 void Nan::ThrowRangeError(const char *msg);
122 void Nan::ThrowRangeError(v8::Local<v8::String> msg);
123 void Nan::ThrowRangeError(v8::Local<v8::Value> error);
124 ```
125
126
127 <a name="api_nan_throw_reference_error"></a>
128 ### Nan::ThrowReferenceError()
129
130 Throw an ReferenceError object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new ReferenceError object will be created.
131
132 Signature:
133
134 ```c++
135 void Nan::ThrowReferenceError(const char *msg);
136 void Nan::ThrowReferenceError(v8::Local<v8::String> msg);
137 void Nan::ThrowReferenceError(v8::Local<v8::Value> error);
138 ```
139
140
141 <a name="api_nan_throw_syntax_error"></a>
142 ### Nan::ThrowSyntaxError()
143
144 Throw an SyntaxError object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new SyntaxError object will be created.
145
146 Signature:
147
148 ```c++
149 void Nan::ThrowSyntaxError(const char *msg);
150 void Nan::ThrowSyntaxError(v8::Local<v8::String> msg);
151 void Nan::ThrowSyntaxError(v8::Local<v8::Value> error);
152 ```
153
154
155 <a name="api_nan_throw_type_error"></a>
156 ### Nan::ThrowTypeError()
157
158 Throw an TypeError object (a specialized `v8::Value` as above) in the current context. If a `msg` is provided, a new TypeError object will be created.
159
160 Signature:
161
162 ```c++
163 void Nan::ThrowTypeError(const char *msg);
164 void Nan::ThrowTypeError(v8::Local<v8::String> msg);
165 void Nan::ThrowTypeError(v8::Local<v8::Value> error);
166 ```
167
168 <a name="api_nan_fatal_exception"></a>
169 ### Nan::FatalException()
170
171 Replaces `node::FatalException()` which has a different API across supported versions of Node. For use with [`Nan::TryCatch`](#api_nan_try_catch).
172
173 Signature:
174
175 ```c++
176 void Nan::FatalException(const Nan::TryCatch& try_catch);
177 ```
178
179 <a name="api_nan_errno_exception"></a>
180 ### Nan::ErrnoException()
181
182 Replaces `node::ErrnoException()` which has a different API across supported versions of Node. 
183
184 Signature:
185
186 ```c++
187 v8::Local<v8::Value> Nan::ErrnoException(int errorno,
188                                          const char* syscall = NULL,
189                                          const char* message = NULL,
190                                          const char* path = NULL);
191 ```
192
193
194 <a name="api_nan_try_catch"></a>
195 ### Nan::TryCatch
196
197 A simple wrapper around [`v8::TryCatch`](https://v8docs.nodesource.com/io.js-3.0/d4/dc6/classv8_1_1_try_catch.html) compatible with all supported versions of V8. Can be used as a direct replacement in most cases. See also [`Nan::FatalException()`](#api_nan_fatal_exception) for an internal use compatible with `node::FatalException`.
198
199 Signature:
200
201 ```c++
202 class Nan::TryCatch {
203  public:
204   Nan::TryCatch();
205
206   bool HasCaught() const;
207
208   bool CanContinue() const;
209
210   v8::Local<v8::Value> ReThrow();
211
212   v8::Local<v8::Value> Exception() const;
213
214   // Nan::MaybeLocal for older versions of V8
215   v8::MaybeLocal<v8::Value> StackTrace() const;
216
217   v8::Local<v8::Message> Message() const;
218
219   void Reset();
220
221   void SetVerbose(bool value);
222
223   void SetCaptureMessage(bool value);
224 };
225 ```
226