It appears that Firefox handles errors differently when they occur in the window.onerror event handler compared to other browsers. While IE, Chrome, and Safari behave as expected, Firefox seems to treat any error in this context as a critical exception, even if it is caught. The issue arises specifically when a non-existent method like abc() is called, resulting in an immediate halt of execution in Firefox without executing the catch block or continuing with the onerror handler.
Could this behavior be intentional in Firefox, or am I overlooking something?
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8>
<title></title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.js"></script>
<script type="text/javascript">
$(document).ready(function() {
window.onerror = function() {
console.log('begin onerror');
try {
abc(); // create a runtime error by calling a method that doesn't exist
} catch(e) {
console.log('catch block');
}
console.log('end onerror');
};
$('#btn').click(function() {
xyz(); // create a runtime error by calling a method that doesn't exist
});
});
</script>
</head>
<body>
<form action="" name="frmEdit">
<input type="button" value="Test" id="btn" name="btn" />
</form>
</body>
</html>