Chapter 16. JavaScript Error Handling

After reading this chapter, you'll be able to

  • Understand error handling using JavaScript methods.

  • Handle errors using try/catch statements.

  • Use try/catch/finally statements.

  • Handle the onerror event for window and image objects.

An Overview of Error Handling

This chapter looks at two primary, built-in ways of handling error conditions in JavaScript. The try/catch statement pair is available in JavaScript. Many languages, such as Microsoft Visual Basic .NET, include this pair of keywords that help the programmer handle error conditions within their code.

Along with try/catch, JavaScript offers the onerror event, which gives the programmer another tool to perform an action when encountering an error.

Using try/catch ...

Get JavaScript Step by Step now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.