By default, Raven makes a few efforts to try it’s best to capture meaningful stack traces, but browsers make it pretty difficult.

The easiest solution is to prevent an error from bubbling all of the way up the stack to window.

How to actually capture an error correctly


The simplest way, is to try and explicitly capture and report potentially problematic code with a try...catch block and Raven.captureException.

try {
} catch(e) {


Raven.context allows you to wrap any function to be immediately executed. Behind the scenes, Raven is just wrapping your code in a try...catch block.

Raven.context(function() {

Raven.wrap wraps a function in a similar way to Raven.context, but instead of executing the function, it returns another function. This is totally awesome for use when passing around a callback.

var doIt = function() {
    // doing cool stuff

setTimeout(Raven.wrap(doIt), 1000)

Tracking authenticated users

While a user is logged in, you can tell Sentry to associate errors with user data.

    email: '',
    id: '123'

If at any point, the user becomes unauthenticated, you can call Raven.setUser() with no arguments to remove their data. This would only really be useful in a large web app where the user logs in/out without a page reload.

Capturing a specific message


Passing additional data

captureException, context, wrap, and captureMessage functions all allow passing additional data to be tagged onto the error, such as tags.

Raven.captureException(e, {tags: { key: "value" }})

Raven.captureMessage('Broken!', {tags: { key: "value" }})

Raven.context({tags: { key: "value" }}, function(){ ... })

Raven.wrap({logger: "my.module"}, function(){ ... })

Dealing with minified source code

Raven and Sentry now support Source Maps. Information coming soon

Project Versions

Table Of Contents

Previous topic


Next topic


This Page