Created
October 7, 2016 12:54
-
-
Save rianby64/3b945dd8dbf308847a6f059c670dca62 to your computer and use it in GitHub Desktop.
A simple demo that shows how to catch all errors through the window.onerror (via addEventListener)
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
<!doctype html> | |
<html> | |
<body> | |
<button>Fire error</button> | |
<script> | |
'use script'; | |
window.addEventListener('error', e => { | |
console.error('catch error', e); | |
}); | |
document.querySelector('button').addEventListener('click', e => { | |
var message = 'this is the message error'; | |
var error = { | |
message: message, | |
filename: 'this is the filename', | |
colno: 4, | |
lineno: 5, | |
error: new Error(message) | |
}; | |
window.dispatchEvent(new ErrorEvent('error', error)); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment