const asyncThrowSampleApiFunction = async () => {
throw new Error('SOMETHING');
};
const MyComponent = (SomeApiFunction) => {
try {
SomeApiFunction();
} catch (err) {
handleMyError(err);
}
return ...;
};
const c = MyComponent(() => {
asyncThrowSampleApiFunction(); // call async function without 'await' or 'Promise.catch'
});
Is there any way to catch an unhandled promise rejection without Promise.catch or await?
In React.useEffect, we often use async function call without await statement. And I want to handle possible asynchronous errors in React.useEffect.
So I want to catch an unhandled promise rejection, but I can only find a global way to catch these rejection types.
(e.g. window.addEventListener('unhandledrejection', ...); )
I want to make my own ErrorBoundary. So I need to catch these rejections locally.
Is there any way to catch them?
Thanks.