Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

trycatch

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trycatch

An asynchronous exception handler with long stack traces for node.js

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
493
increased by11.04%
Maintainers
1
Weekly downloads
 
Created
Source

trycatch

An asynchronous try catch / exception handler with long stack traces for node.js

Background

See the "Background" from the long-stack-traces module.

Install

npm install trycatch

Basic Example

trycatch(function() {
	function f() {
		throw new Error('foo');
	}
	
	setTimeout(f, Math.random()*1000);
	setTimeout(f, Math.random()*1000);
}, function(err) {
	console.log("This is an asynchronous scoped error handler!\n", err.stack);
});
Output
$ node examples/setTimeout.js 
This is an asynchronous scoped error handler!
 Error: foo
    at Object.f (/path/to/trycatch/examples/setTimeout.js:5:9)
    at Timer.callback (timers.js:83:39)
----------------------------------------
    at setTimeout
    at /path/to/trycatch/examples/setTimeout.js:8:2
    at Object.<anonymous> (/path/to/trycatch/examples/setTimeout.js:3:1)
    at Module._compile (module.js:404:26)
    at Object..js (module.js:410:10)
    at Module.load (module.js:336:31)
This is an asynchronous scoped error handler!
 Error: foo
    at Object.f (/path/to/trycatch/examples/setTimeout.js:5:9)
    at Timer.callback (timers.js:83:39)
----------------------------------------
    at setTimeout
    at /path/to/trycatch/examples/setTimeout.js:9:2
    at Object.<anonymous> (/path/to/trycatch/examples/setTimeout.js:3:1)
    at Module._compile (module.js:404:26)
    at Object..js (module.js:410:10)
    at Module.load (module.js:336:31)

Returning 500s on Server Request

http.createServer(function(req, res) {
	trycatch(function() {
		setTimeout(function() {
			throw new Error('Baloney!');
		}, 1000);
	}, function(err) {
		res.writeHead(500);
		res.end(err.stack);
	});
}).listen(8000);

Visit http://localhost:8000 and get your 500.

Keywords

FAQs

Package last updated on 01 Oct 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc