From the course: Introduction to Couchbase

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Handling errors and exceptions

Handling errors and exceptions - Couchbase Tutorial

From the course: Introduction to Couchbase

Handling errors and exceptions

- [Instructor] Okay, so everything is going well, and your code has been running the exact results you want, but what happens when an error or an exception does come up? We all know that errors happen, and the best developers will always test and plan for them. To see how to do that, we'll slip back into the Visual Studio Code IDE. Here, I've written and saved code to remove a document called airline_10. When I go down to the terminal and run the code, I can see that I have a document not found error, also known as a document not found exception in languages other than Node.js. If uncaught, errors could be propagated to the web layer, which can cause headaches for you as the developer. To improve this and to save time, I'll paste a try-catch block into the code. And as you can see here, I've added an error message and a key identifier for the erroring operation. I'll hit File and save the code, and now I'll go into the terminal and run the application. Success, the error is now…

Contents