O'Reilly logo

Professional, JavaScript® for Web Developers, Second Edition by Nicholas C. Zakas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 14. Error Handling and Debugging

JavaScript has traditionally been known as one of the most difficult programming languages to debug due to its dynamic nature and years without proper development tools. Errors typically resulted in confusing browser messages such as "object expected" that provided little or no contextual information. The third edition of ECMAScript aimed to improve this situation, introducing the try-catch and throw statements, along with various error types to help developers deal with errors when they occur. A few years later, JavaScript debuggers and debugging tools began appearing for web browsers. By 2008, most web browsers supported some JavaScript debugging capabilities.

Armed with the proper language support and development tools, web developers are now empowered to implement proper error-handling processes and figure out the cause of problems.

Browser Error Reporting

All of the major web browsers — Internet Explorer (IE), Firefox, Safari, Chrome, and Opera — have some way to report JavaScript errors to the user. By default, all browsers hide this information, because it's of little use to anyone but the developer. When developing browser-based JavaScript solutions, be sure to enable JavaScript error reporting to be notified when there is an error.

Internet Explorer

IE is the only browser that displays a JavaScript error indicator in the browser's chrome by default. When a JavaScript error occurs, a small yellow icon appears in the lower-left corner of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required