O'Reilly logo

JavaScript Recipes: A Problem-Solution Approach by Keith Cirkel, Russ Ferguson

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

© Russ Ferguson and Keith Cirkel 2017
Russ Ferguson and Keith CirkelJavaScript Recipes10.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

new Array(-1) //returns Uncaught RangeError: Invalid array length
//user defined error
console.log(new Error('this is a problem')); //returns ...

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