Chapter 7

Error Handling and Debugging

IN THIS CHAPTER

Bullet Recognizing the types of errors

Bullet Using error objects

Bullet Handling and catching exceptions

Bullet Debugging Node.js programs using the command line and Chrome

“The most formidable weapon against errors of every kind is reason.”

—THOMAS PAINE

Error handling is how you respond to and recover from error conditions in a program. In this chapter, I show you how to handle errors in Node.js and how to find the sources of errors by using debugging tools so that you can prevent them from happening in the future.

Knowing the Types of Errors

Not all errors are the same. Some errors are expected and there's not much that you, as the programmer, can do to prevent them. Other errors are the result of programmer errors. The two types of errors can be referred to as operational errors and programmer errors.

Operational errors

Operational errors happen. How you deal with them determines whether they crash your program, make it unusable, or cause a temporary hiccup. Operational errors include

  • Failure of a remote resource (such as an API server)
  • Network ...

Get JavaScript All-in-One For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.