window.onunhandledrejection = function (error) {
console.error(`Promise failed: ${error.reason}`);
};
Please, please, please don't do this. This to me is exactly as bad as putting your entire application in a try, catch. You'll miss important errors and it'll make debugging a hell. Let your application crash, catch it with a good error reporting tool, and fix it. This is why we run betas and test often.
Hi, my nameβs Aaron Powell and Iβm a Cloud Advocate at Microsoft. My area of specialty is front-end web dev and .NET (especially F#), but I enjoy doing silly things with technology.
You're right, you should have proper error handling as close to where you expect an error to occur and use a monitoring tool (which I blogged about recently) to capture unhandled errors.
The code illustrated in this post is just what these tools do, they attach to the global events like onunhandledrejection and onerror.
The point of this post is to show you how those work so you have a better understanding of just what is happening in the libraries you bring into a project.
Yes, you shouldn't capture a global event and just console.error it, you should do something constructive with it, but the code is for illustrative purposes. π
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Please, please, please don't do this. This to me is exactly as bad as putting your entire application in a
try, catch
. You'll miss important errors and it'll make debugging a hell. Let your application crash, catch it with a good error reporting tool, and fix it. This is why we run betas and test often.You're right, you should have proper error handling as close to where you expect an error to occur and use a monitoring tool (which I blogged about recently) to capture unhandled errors.
The code illustrated in this post is just what these tools do, they attach to the global events like
onunhandledrejection
andonerror
.The point of this post is to show you how those work so you have a better understanding of just what is happening in the libraries you bring into a project.
Yes, you shouldn't capture a global event and just
console.error
it, you should do something constructive with it, but the code is for illustrative purposes. π