Created
May 27, 2018 17:53
-
-
Save softwarespot/279f90fd8a82da8d8751c4440950ceaf to your computer and use it in GitHub Desktop.
Listen for uncaught errors using window.addEventListener('error', ...)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
window.addEventListener('error', (event) => { | |
const { message, filename, lineno, colno, error } = event; | |
console.log('Captured uncaught error:', message, filename, lineno, colno, error.stack); | |
}); | |
setTimeout(() => { | |
try { | |
throw new Error('An unexpected error occurred (2)'); | |
} catch (ex) { | |
// Ignore | |
} | |
}); | |
throw new Error('An unexpected error occurred (1)'); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment