Error Handling in Express Js

Most of the times, the program doesn’t run successfully in the first attempt. The reason can be a syntactic error, a logical error or a runtime error.

Error handling is useful in handling runtime error. If we don’t handle runtime errors, it will result in the incomplete program termination. Using error handling we can display a message or handle the error, so that the program can complete its execution properly.

Using try catch blocks

As we know try-catch blocks are used everywhere to handle errors. But this approach may not handle all types of errors in JS, as JS is based asynchronous methodology.

Using Callbacks

Callbacks are also a function supplied to a function as an argument. After the completion of that function, the callback function is called. In simple terms, callback functions are executed after the completion of asynchronous operations.

Leave a Reply

Your email address will not be published. Required fields are marked *