Try and Catch

Share This Post

The try/catch keywords allow us to handle errors more gracefully. Here is an example…

try {
    let animal = newAnimal;
} catch(error){
    console.log(‘error: ‘, error);
}
console.log(‘code should continue to run…’); 

What we are doing here is telling JavaScript to “try” running the code. If there is an error catch it and do something with it. In this case, we are simply outputting it to the console, but we could log it to a server, etc. The error is caught, but the code does not stop running. If you run this code, you will see the error logged to the console and you should then see the last log statement outside the try/catch.

Happy Coding!

Clay Hess

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Code

Curriculum Innovation or Confusion

It is an early Monday morning just prior to the beginning of the semester.  A faculty member walks into the institution where he teaches.  He

Code

Creating a Promise

Promises are used for asynchronous code. It is a temporary holder for a value that gets returned by an asynchronous call. For example, a call

Do You Want To Boost Your Business?

drop us a line and keep in touch

Questions?Have questions? Ask away!
Scroll to Top
small_c_popup.png

Need help?

Let's have a chat...


Login

Jump Back In!

Here at Webolution Designs, we love to learn. This includes sharing things we have learned with you. 

Register

Begin Your Learning Journey Today!

Come back inside to continue your learning journey.