简体   繁体   English

如何在哨兵的catch语句中记录错误

[英]How to log error in catch statement in sentry

I am new to Sentry and I want to log an error manually.我是 Sentry 的新手,我想手动记录错误。

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我正在使用 RN 项目,但从他们的文档中,RN 扩展了 JS sdk

Consider a function as simple as this考虑像这样简单的 function

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

How can I log thrown error in sentry?如何在哨兵中记录抛出的错误? from my catch block.从我的捕获块。

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");

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.对于某些 SDK,您还可以省略 captureException 的参数,Sentry 将尝试捕获当前异常。 It is also useful for manual reporting of errors or messages to Sentry.它对于手动向 Sentry 报告错误或消息也很有用。

You can read more from the official docs https://docs.sentry.io/platforms/react-native/usage/您可以从官方文档https://docs.sentry.io/platforms/react-native/usage/阅读更多内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM