O'Reilly logo

JavaScript Step by Step by Steve Suehring

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 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 ...

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