Skip to main content

[JavaScript] I'm getting "Object captured as exception with keys" events, what do they mean?

Issue

In the JavaScript SDK, I'm getting unknown events titled "Object captured as exception with keys: ..." with no stack trace and little information. These come from a non-error object (a plain object) being thrown or passed to captureException.

Applies To

  • All SaaS Customers and Self-Hosted Users

  • JavaScript SDK (including React Native and other JavaScript-based SDKs)

Resolution

The JavaScript SDK creates this event when a non-error value, such as a plain object, is thrown or passed to Sentry.captureException() instead of an Error. Because the value is not an Error, the SDK cannot derive a stack trace, so it builds the title from the object's own keys to help you locate the source. For example:

const nonErrorObject = {
keys: "lost",
foo: "bar",
details: "unremarkable",
};

Sentry.captureException(nonErrorObject);
// or
throw nonErrorObject;

This is expected behavior. To resolve it, choose one of the following:

  1. Capture an Error instead (recommended). Find where the non-error object is thrown or captured, and pass an Error instance so the event gets a stack trace and groups correctly:

    Sentry.captureException(new Error("Descriptive message"));
  2. Filter the events if they are expected and you cannot change the source. Add the message to ignoreErrors:

    ignoreErrors: ["Object captured as exception"];

For other ways to filter events, see the JavaScript filtering documentation.

Did this answer your question?