src: refactor uncaught exception handling

The C++ land `node::FatalException()` is not in fact fatal anymore.
It gives the user a chance to handle the uncaught exception
globally by listening to the `uncaughtException` event. This patch
renames it to `TriggerUncaughtException` in C++ to avoid the confusion.

In addition rename the JS land handler to `onGlobalUncaughtException`
to reflect its purpose - we have to keep the alias
`process._fatalException` and use that for now since it has been
monkey-patchable in the user land.

This patch also

- Adds more comments to the global uncaught exception handling routine
- Puts a few other C++ error handling functions into the `errors`
  namespace
- Moves error-handling-related bindings to the `errors` binding.

Refs: https://github.com/nodejs/node/commit/2b252acea47af3ebeac3d7e68277f015667264cc

PR-URL: https://github.com/nodejs/node/pull/28257
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
This commit is contained in:
Joyee Cheung committed 2019-06-19 16:16:37 +08:00
1 parent 1c23b6f2be
commit a33c3c6d33
16 files changed
+190 -158

No files matched your search

+12 -17
View File
@@ -29,21 +29,6 @@ void OnFatalError(const char* location, const char* message);
void PrintErrorString(const char* format, ...);
void ReportException(Environment* env, const v8::TryCatch& try_catch);
void ReportException(Environment* env,
Local<Value> er,
Local<Message> message);
void FatalException(v8::Isolate* isolate,
Local<Value> error,
Local<Message> message);
void FatalException(v8::Isolate* isolate,
Local<Value> error,
Local<Message> message,
bool from_promise);
// Helpers to construct errors similar to the ones provided by
// lib/internal/errors.js.
// Example: with `V(ERR_INVALID_ARG_TYPE, TypeError)`, there will be
@@ -190,14 +175,24 @@ class TryCatchScope : public v8::TryCatch {
CatchMode mode_;
};
// Trigger the global uncaught exception handler `process._fatalException`
// in JS land (which emits the 'uncaughtException' event). If that returns
// true, continue program execution, otherwise exit the process.
void TriggerUncaughtException(v8::Isolate* isolate,
const v8::TryCatch& try_catch);
void TriggerUncaughtException(v8::Isolate* isolate,
Local<Value> error,
Local<Message> message,
bool from_promise = false);
const char* errno_string(int errorno);
void PerIsolateMessageListener(v8::Local<v8::Message> message,
v8::Local<v8::Value> error);
} // namespace errors
void DecorateErrorStack(Environment* env,
const errors::TryCatchScope& try_catch);
} // namespace errors
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS