How to log error in catch statement in sentry
Asked Answered
O

2

8

I am new to Sentry and I want to log an error manually.

For some reason I am unable to find in their docs, how I can achieve this

I am using RN project but from their docs, RN extends JS sdk

Consider a function as simple as this

const logErrorIntentionally = () => {
 try {
  } catch (error) {
  //throw sentry error here
  }
}

How can I log thrown error in sentry? from my catch block.

Outrider answered 6/3, 2021 at 7:0 Comment(0)
Z
19

According to the docs:

import * as Sentry from '@sentry/browser';

try {
  aFunctionThatMightFail();
} catch (err) {
  Sentry.captureException(err);
}

For custom messages:

import * as Sentry from '@sentry/browser';

Sentry.captureMessage("Something went wrong");
Zonda answered 1/4, 2021 at 7:51 Comment(1)
Where do captured messages appear in the Sentry UI?Blankbook
B
0

The most common form of capturing is to capture errors. What can be captured as an error varies by platform. In general, if you have something that looks like an exception, it can be captured. For some SDKs, you can also omit the argument to captureException and Sentry will attempt to capture the current exception. It is also useful for manual reporting of errors or messages to Sentry.

You can read more from the official docs https://docs.sentry.io/platforms/react-native/usage/

Burgle answered 19/7, 2021 at 3:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.