trycatch
A domain-based asynchronous try/catch with (optional) long stack traces for node.js optimized for V8.
WARNING: trycatch replaces the built-in global Error object.
Install
npm install trycatch
Use
var trycatch =
Returning 500s on Server Request
http;
Visit http://localhost:8000 and get your 500.
Options
Optional Long-Stack-Traces:
// Because trycatch shims all native I/O calls,// it must be required & configured with 'long-stack-traces' before any other modules.var trycatch = trycatch
Colors:
var trycatch = trycatch
Advanced Formatting:
var trycatch = trycatch
Basic Example
var trycatch = _ = _ ;
Output
Advanced Examples
See the /test
and examples
directories for more use cases.
uncaughtApplicationException
trycatch
effectively wraps all application callbacks in try/catch
blocks, preventing an exception in your application code from causing code in core to not execute. Effectively, this means that excpeitons originating in application code that normally would be passed as uncaughtException
, can instead be handled via uncaughtApplicationException
without requiring a restart:
process.on('uncaughtApplicationException', (err) => console.log(err.stack)) process.on('uncaughtException', (err) => { console.log(err.stack) // We are in an undefined state and need to restart handleSoftShutodwn()})