Simple question about try-catch for function in setTimeout
try {
setTimeout(function () {
throw new Error(\'error!\');
}, 300)
} catch (e) {
A bit strange solution, but sometimes it would be useful maybe...
function globalErrorHandler(e) {
console.warn('eeee!')
console.warn(e);
}
const _setTimeoutOriginal = setTimeout;
setTimeout = function(callback, timeout) {
const args = Array.from(arguments).slice(2);
_setTimeoutOriginal(function() {
try {
callback.apply(this, args);
} catch (e) {
globalErrorHandler(e);
}
}, timeout);
};
setTimeout(function() {
throw new Error('error!');
}, 300)