Este artículo describe cómo JS usa OnError para atrapar excepciones. Compártelo para su referencia, como sigue:
Si necesita utilizar el evento OnError, debe crear una función que maneja el error. Puede llamar a esta función OnError Event Handler. Este controlador de eventos usa tres parámetros para llamar: MSG (mensaje de error), URL (URL de la página donde ocurrió el error) y la línea (línea del código donde ocurrió el error).
<HEAD> <script type = "text/javaScript"> onErRor = handleErRvar txt = "" Function HandleErR (msg, url, l) {txt = "Hubo un error en esta página./n/n/n"txt+="ERROR:" + msg + "/n" txt + = "url:" + Url + "/n" txt + = "line:" + l + "/n/n" " continuar./n/n"alert(txt)Return true} función mensaje () {addDlert ("¡Bienvenido invitado!")} </script> </head> <body> <input type = "button" value = "ver mensaje" onclick = "mensaje ()"/> </body> </html>For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript Errors and Debugging Skills", "Summary of JavaScript Mathematical Operation Usage", "Summary of JSON Operation Skills in JavaScript", "Summary of JavaScript Switching Special Effects and Skills", "Summary of JavaScript Search Algorithm Skills", "Summary of JavaScript Animation Special Effects and Habilidades "," Resumen de las estructuras de datos de JavaScript y las habilidades de algoritmo "y" Resumen del algoritmo y habilidades transversales de JavaScript "
Espero que este artículo sea útil para la programación de JavaScript de todos.