错误处理
【Error handling】
如果任何 AsyncHook 回调抛出异常,应用将打印堆栈跟踪并退出。退出路径确实与未捕获异常的路径相同,但所有 'uncaughtException' 监听器都已被移除,因此强制进程退出。除非应用使用 --abort-on-uncaught-exception 运行,否则 'exit' 回调仍会被调用,在这种情况下,会打印堆栈跟踪并应用退出,同时生成核心文件。
【If any AsyncHook callbacks throw, the application will print the stack trace
and exit. The exit path does follow that of an uncaught exception, but
all 'uncaughtException' listeners are removed, thus forcing the process to
exit. The 'exit' callbacks will still be called unless the application is run
with --abort-on-uncaught-exception, in which case a stack trace will be
printed and the application exits, leaving a core file.】
这种错误处理行为的原因是,这些回调可能在对象生命周期中不稳定的时刻运行,例如在类的构造和析构过程中。因此,被认为有必要迅速终止进程,以防止将来发生意外中止。如果将来进行全面分析以确保异常可以在不产生意外副作用的情况下遵循正常的控制流程,这种行为可能会发生变化。
【The reason for this error handling behavior is that these callbacks are running at potentially volatile points in an object's lifetime, for example during class construction and destruction. Because of this, it is deemed necessary to bring down the process quickly in order to prevent an unintentional abort in the future. This is subject to change in the future if a comprehensive analysis is performed to ensure an exception can follow the normal control flow without unintentional side effects.】