Error Handling and Debugging

Nicholas C. Zakas · 2015

Error handling in JavaScript is critical for today's complex web applications. Most browsers do not report JavaScript errors to users by default, so we need to enable error reporting when developing and debugging. This chapter discusses methods that can be used to prevent the browser from reacting to a JavaScript error. The try-catch statement can be used where errors may occur, giving us the opportunity to respond to errors in an appropriate way instead of allowing the browser to handle the error. Another option is to use the window.onerror event handler, which receives all errors that are not handled by a try-catch Internet Explorer, Firefox, and Chrome only. Errors commonly occur in JavaScript because of type coercion, insufficient data type checking, and incorrect data being sent to or received from the server. Internet Explorer, Firefox, Chrome, Opera, and Safari each have JavaScript debuggers.

Read the paper · More papers on PaperTik