오류 이벤트 핸들러는 JavaScript에서 오류 처리를 용이하게 하는 첫 번째 기능이었습니다. 페이지에서 예외가 발생할 때마다 창 개체에서 오류 이벤트가 발생합니다.
예시
다음 코드를 실행하여 JavaScript에서 onerror() 메서드를 구현할 수 있습니다. -
<html>
<head>
<script>
<!--
window.onerror = function () {
alert("An error occurred.");
}
//-->
</script>
</head>
<body>
<p>Click the following to see the result:</p>
<form>
<input type = "button" value = "Click Me" onclick = "myFunc();" />
</form>
</body>
</html>