I use React and have a code as this:
<code>export default App;
window.onerror = function(error) {alert("Error caught: " + error);};
function App() {
perform().catch((error) =>{
console.error('Error: '+error);
throw error;
});
}
async function perform() {
throw Error("here");
}
</code>
<code>export default App;
window.onerror = function(error) {alert("Error caught: " + error);};
function App() {
perform().catch((error) =>{
console.error('Error: '+error);
throw error;
});
}
async function perform() {
throw Error("here");
}
</code>
export default App;
window.onerror = function(error) {alert("Error caught: " + error);};
function App() {
perform().catch((error) =>{
console.error('Error: '+error);
throw error;
});
}
async function perform() {
throw Error("here");
}
But window.onerror is never invoked. Any ideas why?
0
<code>perform().catch((error) =>{
console.error('Error: '+error);
throw error;
});
</code>
<code>perform().catch((error) =>{
console.error('Error: '+error);
throw error;
});
</code>
perform().catch((error) =>{
console.error('Error: '+error);
throw error;
});
This throw
is happening in the callback of a promise, so it causes the promise to reject. window.onerror doesn’t get called for unhandled promise rejections. For that, you can do:
<code>window.onunhandledrejection = function (event) {
alert("Error caught: " + event.reason);
}
</code>
<code>window.onunhandledrejection = function (event) {
alert("Error caught: " + event.reason);
}
</code>
window.onunhandledrejection = function (event) {
alert("Error caught: " + event.reason);
}