JavaScript

Errors

Objectives

  • Define the term "Error" as it relates to JavaScript.
  • Read a "Stack Trace" to extract the following information:
    • The  line of code where the error occurred.
    • The type of error that occurred.
    • What path the code traveled to get to that line.
  • Use a try/catch block to handle expected errors.
  • Throw a custom error.

What are errors...?

var someObject = {
    property = 7;
}
console.log(undef);
var sensibleArray =
new Array(-1);
var num = 4;
num();

What are errors...?

Impossible!

Unreasonable!

requests

&

How does JS handle errors?

It terminates the whole program...

What if a user submits an invalid email?

try {
} catch(error){
}

Custom errors - why?

JavaScript Errors

By Dize Hacioglu

JavaScript Errors

  • 167