3

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.

Cyberduck
  • 571
  • 3
  • 6
  • 12

2 Answers2

10

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");
Ole
  • 480
  • 4
  • 11
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/

iammtander
  • 111
  • 1
  • 2