Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “重击不触发”;window.onerror";事件_Javascript_Reactjs_Typescript_Error Handling_Redux - Fatal编程技术网

Javascript “重击不触发”;window.onerror";事件

Javascript “重击不触发”;window.onerror";事件,javascript,reactjs,typescript,error-handling,redux,Javascript,Reactjs,Typescript,Error Handling,Redux,我正在尝试使用window.onerror添加全局错误日志记录,如中所述 当我在我的一个组件生命周期方法和同步redux操作中抛出错误时,它就可以工作了。但是,异步thunk操作引发的错误不会被我的处理程序捕获 这是预期的吗?是否有某种方法可以在全局处理程序中捕获这些错误 export const syncReduxAction = (): Action => { throw 'This will trigger window.onerror'; }; export const as

我正在尝试使用
window.onerror
添加全局错误日志记录,如中所述

当我在我的一个组件生命周期方法和同步redux操作中抛出错误时,它就可以工作了。但是,异步
thunk
操作引发的错误不会被我的处理程序捕获

这是预期的吗?是否有某种方法可以在全局处理程序中捕获这些错误

export const syncReduxAction = (): Action => {
  throw 'This will trigger window.onerror';
};

export const asyncReduxAction = (): ThunkAction<Promise<T>, GlobalState, void> =>
  async (dispatch, getState) => {
    throw 'This will NOT trigger window.onerror';
}
它不会触发事件

this.props.dispatch(asyncReduxAction())
.catch((e)=> {
   throw new Error(e);
  }
);