Learn
Learn JavaScript: Error Handling
Error Handling Review
Great job with handling errors!
In this lesson we went over:
- How mistakes in programming leads to errors.
- Why errors are useful for developers.
- Errors will prevent a program from executing unless it is handled.
- How to create an error using the
Error()
function. - How to throw an error object using the
throw
keyword. - How to use the
try...catch
statement to handle thrown errors. - Evaluating code in a
try
block to anticipate errors. - Catching the error in a
catch
block to allow our program to continue running. - Why the
try...catch
statement would be useful in a program.
Now you have the ability to create code that doesn’t break when an error is thrown!
Instructions
If you want to challenge yourself:
- Force different built-in error object to be thrown in a
try...catch
statement and see when the messages are different. - Test out what different data types you can throw.
- Use
try...catch
for a function that accepts user input to allow errors to be thrown but your program to continue running.