From a33c3c6d33fa81fa59a5aa95246d7f599e6abdd3 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 15 Jun 2019 08:07:15 +0800 Subject: 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 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Franziska Hinkelmann --- src/api/exceptions.cc | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/api') diff --git a/src/api/exceptions.cc b/src/api/exceptions.cc index ee5ea984eb..1632574c6b 100644 --- a/src/api/exceptions.cc +++ b/src/api/exceptions.cc @@ -244,17 +244,12 @@ Local WinapiErrnoException(Isolate* isolate, } #endif +// Implement the legacy name exposed in node.h. This has not been in fact +// fatal any more, as the user can handle the exception in the +// TryCatch by listening to `uncaughtException`. +// TODO(joyeecheung): deprecate it in favor of a more accurate name. void FatalException(Isolate* isolate, const v8::TryCatch& try_catch) { - // If we try to print out a termination exception, we'd just get 'null', - // so just crashing here with that information seems like a better idea, - // and in particular it seems like we should handle terminations at the call - // site for this function rather than by printing them out somewhere. - CHECK(!try_catch.HasTerminated()); - - HandleScope scope(isolate); - if (!try_catch.IsVerbose()) { - FatalException(isolate, try_catch.Exception(), try_catch.Message()); - } + errors::TriggerUncaughtException(isolate, try_catch); } } // namespace node -- cgit v1.2.3