Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

errors.md 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. ## Errors
  2. 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.
  3. Note that an Error object is simply a specialized form of `v8::Value`.
  4. Also consult the V8 Embedders Guide section on [Exceptions](https://developers.google.com/v8/embed#exceptions) for more information.
  5. - <a href="#api_nan_error"><b><code>Nan::Error()</code></b></a>
  6. - <a href="#api_nan_range_error"><b><code>Nan::RangeError()</code></b></a>
  7. - <a href="#api_nan_reference_error"><b><code>Nan::ReferenceError()</code></b></a>
  8. - <a href="#api_nan_syntax_error"><b><code>Nan::SyntaxError()</code></b></a>
  9. - <a href="#api_nan_type_error"><b><code>Nan::TypeError()</code></b></a>
  10. - <a href="#api_nan_throw_error"><b><code>Nan::ThrowError()</code></b></a>
  11. - <a href="#api_nan_throw_range_error"><b><code>Nan::ThrowRangeError()</code></b></a>
  12. - <a href="#api_nan_throw_reference_error"><b><code>Nan::ThrowReferenceError()</code></b></a>
  13. - <a href="#api_nan_throw_syntax_error"><b><code>Nan::ThrowSyntaxError()</code></b></a>
  14. - <a href="#api_nan_throw_type_error"><b><code>Nan::ThrowTypeError()</code></b></a>
  15. - <a href="#api_nan_fatal_exception"><b><code>Nan::FatalException()</code></b></a>
  16. - <a href="#api_nan_errno_exception"><b><code>Nan::ErrnoException()</code></b></a>
  17. - <a href="#api_nan_try_catch"><b><code>Nan::TryCatch</code></b></a>
  18. <a name="api_nan_error"></a>
  19. ### Nan::Error()
  20. Create a new Error object using the [v8::Exception](https://v8docs.nodesource.com/node-8.11/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8.
  21. Note that an Error object is simply a specialized form of `v8::Value`.
  22. Signature:
  23. ```c++
  24. v8::Local<v8::Value> Nan::Error(const char *msg);
  25. v8::Local<v8::Value> Nan::Error(v8::Local<v8::String> msg);
  26. ```
  27. <a name="api_nan_range_error"></a>
  28. ### Nan::RangeError()
  29. Create a new RangeError object using the [v8::Exception](https://v8docs.nodesource.com/node-8.11/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8.
  30. Note that an RangeError object is simply a specialized form of `v8::Value`.
  31. Signature:
  32. ```c++
  33. v8::Local<v8::Value> Nan::RangeError(const char *msg);
  34. v8::Local<v8::Value> Nan::RangeError(v8::Local<v8::String> msg);
  35. ```
  36. <a name="api_nan_reference_error"></a>
  37. ### Nan::ReferenceError()
  38. Create a new ReferenceError object using the [v8::Exception](https://v8docs.nodesource.com/node-8.11/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8.
  39. Note that an ReferenceError object is simply a specialized form of `v8::Value`.
  40. Signature:
  41. ```c++
  42. v8::Local<v8::Value> Nan::ReferenceError(const char *msg);
  43. v8::Local<v8::Value> Nan::ReferenceError(v8::Local<v8::String> msg);
  44. ```
  45. <a name="api_nan_syntax_error"></a>
  46. ### Nan::SyntaxError()
  47. Create a new SyntaxError object using the [v8::Exception](https://v8docs.nodesource.com/node-8.11/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8.
  48. Note that an SyntaxError object is simply a specialized form of `v8::Value`.
  49. Signature:
  50. ```c++
  51. v8::Local<v8::Value> Nan::SyntaxError(const char *msg);
  52. v8::Local<v8::Value> Nan::SyntaxError(v8::Local<v8::String> msg);
  53. ```
  54. <a name="api_nan_type_error"></a>
  55. ### Nan::TypeError()
  56. Create a new TypeError object using the [v8::Exception](https://v8docs.nodesource.com/node-8.11/da/d6a/classv8_1_1_exception.html) class in a way that is compatible across the supported versions of V8.
  57. Note that an TypeError object is simply a specialized form of `v8::Value`.
  58. Signature:
  59. ```c++
  60. v8::Local<v8::Value> Nan::TypeError(const char *msg);
  61. v8::Local<v8::Value> Nan::TypeError(v8::Local<v8::String> msg);
  62. ```
  63. <a name="api_nan_throw_error"></a>
  64. ### Nan::ThrowError()
  65. 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.
  66. Signature:
  67. ```c++
  68. void Nan::ThrowError(const char *msg);
  69. void Nan::ThrowError(v8::Local<v8::String> msg);
  70. void Nan::ThrowError(v8::Local<v8::Value> error);
  71. ```
  72. <a name="api_nan_throw_range_error"></a>
  73. ### Nan::ThrowRangeError()
  74. 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.
  75. Signature:
  76. ```c++
  77. void Nan::ThrowRangeError(const char *msg);
  78. void Nan::ThrowRangeError(v8::Local<v8::String> msg);
  79. void Nan::ThrowRangeError(v8::Local<v8::Value> error);
  80. ```
  81. <a name="api_nan_throw_reference_error"></a>
  82. ### Nan::ThrowReferenceError()
  83. 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.
  84. Signature:
  85. ```c++
  86. void Nan::ThrowReferenceError(const char *msg);
  87. void Nan::ThrowReferenceError(v8::Local<v8::String> msg);
  88. void Nan::ThrowReferenceError(v8::Local<v8::Value> error);
  89. ```
  90. <a name="api_nan_throw_syntax_error"></a>
  91. ### Nan::ThrowSyntaxError()
  92. 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.
  93. Signature:
  94. ```c++
  95. void Nan::ThrowSyntaxError(const char *msg);
  96. void Nan::ThrowSyntaxError(v8::Local<v8::String> msg);
  97. void Nan::ThrowSyntaxError(v8::Local<v8::Value> error);
  98. ```
  99. <a name="api_nan_throw_type_error"></a>
  100. ### Nan::ThrowTypeError()
  101. 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.
  102. Signature:
  103. ```c++
  104. void Nan::ThrowTypeError(const char *msg);
  105. void Nan::ThrowTypeError(v8::Local<v8::String> msg);
  106. void Nan::ThrowTypeError(v8::Local<v8::Value> error);
  107. ```
  108. <a name="api_nan_fatal_exception"></a>
  109. ### Nan::FatalException()
  110. Replaces `node::FatalException()` which has a different API across supported versions of Node. For use with [`Nan::TryCatch`](#api_nan_try_catch).
  111. Signature:
  112. ```c++
  113. void Nan::FatalException(const Nan::TryCatch& try_catch);
  114. ```
  115. <a name="api_nan_errno_exception"></a>
  116. ### Nan::ErrnoException()
  117. Replaces `node::ErrnoException()` which has a different API across supported versions of Node.
  118. Signature:
  119. ```c++
  120. v8::Local<v8::Value> Nan::ErrnoException(int errorno,
  121. const char* syscall = NULL,
  122. const char* message = NULL,
  123. const char* path = NULL);
  124. ```
  125. <a name="api_nan_try_catch"></a>
  126. ### Nan::TryCatch
  127. A simple wrapper around [`v8::TryCatch`](https://v8docs.nodesource.com/node-8.11/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`.
  128. Signature:
  129. ```c++
  130. class Nan::TryCatch {
  131. public:
  132. Nan::TryCatch();
  133. bool HasCaught() const;
  134. bool CanContinue() const;
  135. v8::Local<v8::Value> ReThrow();
  136. v8::Local<v8::Value> Exception() const;
  137. // Nan::MaybeLocal for older versions of V8
  138. v8::MaybeLocal<v8::Value> StackTrace() const;
  139. v8::Local<v8::Message> Message() const;
  140. void Reset();
  141. void SetVerbose(bool value);
  142. void SetCaptureMessage(bool value);
  143. };
  144. ```