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.1.5
  • 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

Now PRODUCTION Ready!

With the update to 0.1.0, stack traces are now lazy, and all try/catch blocks conform to V8 best practices.

Install

npm install trycatch

Use

Because trycatch shims all native I/O calls, it must be required before any other modules.

var trycatch = require('trycatch')
trycatch(fnTry, fnCatch)

Basic Example


    var trycatch = require("trycatch"),
      _ = require('underscore')._

    trycatch(function() {
      _.map(['Error 1', 'Error 2'], function foo(v) {
        setTimeout(function() {
          throw new Error(v)
        }, 10)
      })
    }, function(err) {
      console.log("Async error caught!\n", err.stack);
    });
Output

Advanced Examples

See the /test and examples directories for more use cases.

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.

Thanks

Special thanks to Tom Robinson for his long-stack-traces module and Tim Caswell who built out the initial hook.js code.

Keywords

FAQs

Package last updated on 06 Dec 2012

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