Introduction
Global exception handling module. Registers uncaughtException and unhandledRejection listeners to catch unhandled exceptions and Promise rejections, logs them, and decides whether to exit the process based on configuration. Called first during framework startup by boot.ts's init(), ensuring exceptions in subsequent flows can be caught.
Enabled in both the main process and ChildJob child processes.
Import
Both CJS and ESM:
// ESM
import { loadException, uncaughtExceptionMonitorHandler } from 'ee-core/exception';
// CJS
const { loadException, uncaughtExceptionMonitorHandler } = require('ee-core/exception');API
loadException()
Description: Register global uncaughtException and unhandledRejection handlers. Should be called at the earliest stage of application startup. The framework calls this automatically during ElectronEgg.init(). Parameters: None Returns: voidExample:
import { loadException } from 'ee-core/exception';
loadException();See also: Called automatically in boot.ts during ElectronEgg.init()
uncaughtExceptionMonitorHandler()
Description: Register an uncaughtExceptionMonitor listener. Unlike uncaughtException, this handler is triggered before the exception is caught, and can be used for exception monitoring and reporting without affecting the subsequent exception handling flow. Useful for sending exception data to external monitoring services. Parameters: None Returns: voidExample:
import { uncaughtExceptionMonitorHandler } from 'ee-core/exception';
// Register monitor for external reporting (does not affect normal exception handling)
uncaughtExceptionMonitorHandler();See also: loadException()
Behavior Details
Exception Configuration
The _exit() function checks the exception section of the app configuration to decide whether to exit the process after an unhandled exception:
| Config Key | Process Type | Default | Description |
|---|---|---|---|
mainExit | Main process | false | Whether the main process exits on uncaught exception |
childExit | Child (forked) process | false | Whether child processes exit on uncaught exception |
rendererExit | Renderer process | false | Whether the renderer process exits on uncaught exception |
Delayed Exit
When exit is configured, the process exits after a 1500ms delay, allowing async operations like log writes to complete before the process terminates.
Child Process Error Visibility
In development mode, forked child processes send error information to the terminal via childMessage.sendErrorToTerminal(), making child process exceptions visible directly in the main terminal.
Logger Fallback
If coreLogger fails (e.g. pino transport unavailable in child processes), the module falls back to console.error so exceptions are never silently swallowed.
