Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

errors.md 7.2KB

Errors

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.

Note that an Error object is simply a specialized form of v8::Value.

Also consult the V8 Embedders Guide section on Exceptions for more information.

Nan::Error()

Create a new Error object using the v8::Exception class in a way that is compatible across the supported versions of V8.

Note that an Error object is simply a specialized form of v8::Value.

Signature:

v8::Local<v8::Value> Nan::Error(const char *msg);
v8::Local<v8::Value> Nan::Error(v8::Local<v8::String> msg);

Nan::RangeError()

Create a new RangeError object using the v8::Exception class in a way that is compatible across the supported versions of V8.

Note that an RangeError object is simply a specialized form of v8::Value.

Signature:

v8::Local<v8::Value> Nan::RangeError(const char *msg);
v8::Local<v8::Value> Nan::RangeError(v8::Local<v8::String> msg);

Nan::ReferenceError()

Create a new ReferenceError object using the v8::Exception class in a way that is compatible across the supported versions of V8.

Note that an ReferenceError object is simply a specialized form of v8::Value.

Signature:

v8::Local<v8::Value> Nan::ReferenceError(const char *msg);
v8::Local<v8::Value> Nan::ReferenceError(v8::Local<v8::String> msg);

Nan::SyntaxError()

Create a new SyntaxError object using the v8::Exception class in a way that is compatible across the supported versions of V8.

Note that an SyntaxError object is simply a specialized form of v8::Value.

Signature:

v8::Local<v8::Value> Nan::SyntaxError(const char *msg);
v8::Local<v8::Value> Nan::SyntaxError(v8::Local<v8::String> msg);

Nan::TypeError()

Create a new TypeError object using the v8::Exception class in a way that is compatible across the supported versions of V8.

Note that an TypeError object is simply a specialized form of v8::Value.

Signature:

v8::Local<v8::Value> Nan::TypeError(const char *msg);
v8::Local<v8::Value> Nan::TypeError(v8::Local<v8::String> msg);

Nan::ThrowError()

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.

Signature:

void Nan::ThrowError(const char *msg);
void Nan::ThrowError(v8::Local<v8::String> msg);
void Nan::ThrowError(v8::Local<v8::Value> error);

Nan::ThrowRangeError()

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.

Signature:

void Nan::ThrowRangeError(const char *msg);
void Nan::ThrowRangeError(v8::Local<v8::String> msg);
void Nan::ThrowRangeError(v8::Local<v8::Value> error);

Nan::ThrowReferenceError()

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.

Signature:

void Nan::ThrowReferenceError(const char *msg);
void Nan::ThrowReferenceError(v8::Local<v8::String> msg);
void Nan::ThrowReferenceError(v8::Local<v8::Value> error);

Nan::ThrowSyntaxError()

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.

Signature:

void Nan::ThrowSyntaxError(const char *msg);
void Nan::ThrowSyntaxError(v8::Local<v8::String> msg);
void Nan::ThrowSyntaxError(v8::Local<v8::Value> error);

Nan::ThrowTypeError()

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.

Signature:

void Nan::ThrowTypeError(const char *msg);
void Nan::ThrowTypeError(v8::Local<v8::String> msg);
void Nan::ThrowTypeError(v8::Local<v8::Value> error);

Nan::FatalException()

Replaces node::FatalException() which has a different API across supported versions of Node. For use with Nan::TryCatch.

Signature:

void Nan::FatalException(const Nan::TryCatch& try_catch);

Nan::ErrnoException()

Replaces node::ErrnoException() which has a different API across supported versions of Node.

Signature:

v8::Local<v8::Value> Nan::ErrnoException(int errorno,
                                         const char* syscall = NULL,
                                         const char* message = NULL,
                                         const char* path = NULL);

Nan::TryCatch

A simple wrapper around v8::TryCatch compatible with all supported versions of V8. Can be used as a direct replacement in most cases. See also Nan::FatalException() for an internal use compatible with node::FatalException.

Signature:

class Nan::TryCatch {
 public:
  Nan::TryCatch();

  bool HasCaught() const;

  bool CanContinue() const;

  v8::Local<v8::Value> ReThrow();

  v8::Local<v8::Value> Exception() const;

  // Nan::MaybeLocal for older versions of V8
  v8::MaybeLocal<v8::Value> StackTrace() const;

  v8::Local<v8::Message> Message() const;

  void Reset();

  void SetVerbose(bool value);

  void SetCaptureMessage(bool value);
};