Skip to content

Instantly share code, notes, and snippets.

@softwarespot
Created May 27, 2018 17:53
Show Gist options
  • Save softwarespot/279f90fd8a82da8d8751c4440950ceaf to your computer and use it in GitHub Desktop.
Save softwarespot/279f90fd8a82da8d8751c4440950ceaf to your computer and use it in GitHub Desktop.
Listen for uncaught errors using window.addEventListener('error', ...)
<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