© Russ Ferguson and Keith Cirkel 2017

Russ Ferguson and Keith Cirkel, JavaScript Recipes, 10.1007/978-1-4302-6107-0_19

19. Debugging and Handling Exceptions

Russ Ferguson and Keith Cirkel2

(1)Ocean, New Jersey, USA

(2)London, UK

What Is an Error in JavaScript?

Problem

How do errors occur and can you create an error object?

Solution

Errors result when there is a problem with code execution in the runtime . When this happens, the runtime will generate an Error object with information about what just happened. There are instances where developers can create user-defined errors that can be useful when debugging.

The Code

Listing 19-1. Two Types of Errors, One During Runtime, the Other User-Defined
new Array(-1) //returns Uncaught RangeError: Invalid array ...

Get JavaScript Recipes: A Problem-Solution Approach 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.