美文网首页RN知识
RN-ErrorUtils处理崩溃、promise错误

RN-ErrorUtils处理崩溃、promise错误

作者: 精神病患者link常 | 来源:发表于2019-01-11 17:17 被阅读11次

ErrorUtils.js路径

image.png

promise路径

image.png

ErrorUtils使用

const ErrorUtils = require('ErrorUtils');
global.ErrorUtils
// error 错误信息
// isFatal 是否崩溃
global.ErrorUtils.setGlobalHandler((error, isFatal)=>{
    JSON.stringify(error.message)
    JSON.stringify(error. stack)
})
ErrorUtils.setGlobalHandler((error, isFatal)=>{
    JSON.stringify(error)
})

promise使用

require('promise/setimmediate/rejection-tracking').enable({
    allRejections: true,
    onUnhandled: (id, error = {}) => {
      let message: string;
      let stack: ?string;

      const stringValue = Object.prototype.toString.call(error);
      if (stringValue === '[object Error]') {
        message = Error.prototype.toString.call(error);
        stack = error.stack;
      } else {
        /* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses
         * an error found when Flow v0.54 was deployed. To see the error delete
         * this comment and run Flow. */
        message = require('pretty-format')(error);
      }

      const warning =
        `Possible Unhandled Promise Rejection (id: ${id}):\n` +
        `${message}\n` +
        (stack == null ? '' : stack);
      console.warn(warning);
    },
    onHandled: (id) => {
      const warning =
        `Promise Rejection Handled (id: ${id})\n` +
        'This means you can ignore any previous messages of the form ' +
        `"Possible Unhandled Promise Rejection (id: ${id}):"`;
      console.warn(warning);
    },
  });

相关文章

  • RN-ErrorUtils处理崩溃、promise错误

    ErrorUtils.js路径 promise路径 ErrorUtils使用 promise使用

  • 详解ES6 Promise

    整理Promise提供的各种方法和错误处理方法。 1.Promise.resolve() 1.1 Promise....

  • Go基础编程---异常处理和文件处理、json、字符串转换..

    异常处理 error 接口 (非致命错误) panic( 致命错误,程序崩溃) recover (防止程序崩溃导致...

  • promise

    1、 2、promise新建后立即执行: 3、try和catch不能处理异步的错误,只能处理同步的错误,所以pro...

  • await

    await获取的是Promise执行成功的结果,并不能处理错误,所以需要使用try-catch来处理错误。

  • Promise 源码与分析

    Promise 介绍 什么是 Promise?解决哪些问题? 回调地狱,代码不好维护,错误处理非常的麻烦,不能统一...

  • 捕获未处理的Promise错误

    译者按: 通过监听unhandledrejection事件,可以捕获未处理的Promise错误。 原文: Trac...

  • ES6-Promise

    构建Promise,异步实例 处理多个Promise实例 — Promise.all() 处理多个Promise实...

  • 【promise-03】 处理错误

    #Promise - 处理错误 首先要知道,then(resolve,reject)中的两个方法都是异步的,所以t...

  • 【一起来烧脑】读懂Promise知识体系

    知识体系 Promise基础语法,如何处理错误,简单介绍异步函数 内容 错误处理的两种方式: 推荐第二种 4个案例...

网友评论

    本文标题:RN-ErrorUtils处理崩溃、promise错误

    本文链接:https://www.haomeiwen.com/subject/rnnxdqtx.html