I’m finding that with asynchronous callbacks I’m needing to write a try/catch for each callback function. It seems a bit error prone is there a method or technique whereby I can implement a single top level try/catch that catches everything? If not is the technique that I’m using considered good practice or is there a better way to do things?
I’m finding that with asynchronous callbacks I’m needing to write a try/catch for each
Share
There is two ways of doing this:
onerrorattributetrue(!) prevents the default error handling (making this something like a catch-all)errorevent listener towindoweas its sole argumente.preventDefault()prevents default error handlingDue to the dynamic nature of JavaScript,
try/catchis very slow. There’s almost always better ways, for example: check if something exists before calling a method on it.For your specific situation, please show some of your code; maybe in a separate question.