Recall & Review
beginner
What is error-handling middleware in Express?
Error-handling middleware is a special type of middleware in Express that catches and processes errors occurring in the app. It has four parameters: (err, req, res, next).
Click to reveal answer
beginner
How do you define an error-handling middleware function in Express?
You define it with four parameters: (err, req, res, next). For example: function (err, req, res, next) { /* handle error */ }.
Click to reveal answer
intermediate
Why must error-handling middleware have four parameters?
Express uses the number of parameters to identify error-handling middleware. Having four parameters tells Express this middleware handles errors.
Click to reveal answer
intermediate
Where should error-handling middleware be placed in the middleware stack?
It should be placed after all other middleware and routes, so it can catch errors from them.
Click to reveal answer
beginner
What happens if you call next() with an error inside a route handler?
Calling next(err) passes the error to the next error-handling middleware, skipping normal middleware.
Click to reveal answer
Which of the following is the correct signature for an Express error-handling middleware?
✗ Incorrect
Error-handling middleware must have four parameters: err, req, res, and next.
Where should you place error-handling middleware in your Express app?
✗ Incorrect
Error-handling middleware should be last to catch errors from all previous middleware and routes.
What does calling next(err) inside a route handler do?
✗ Incorrect
Calling next with an error passes control to the next error-handling middleware.
If an error occurs in a route and you don't have error-handling middleware, what happens?
✗ Incorrect
Express has a default error handler that sends a generic error response if no custom error middleware is defined.
Which parameter in error-handling middleware holds the error object?
✗ Incorrect
The first parameter, err, contains the error passed to the middleware.
Explain how error-handling middleware works in Express and why it needs four parameters.
Think about how Express knows which middleware handles errors.
You got /4 concepts.
Describe the steps to add custom error handling to an Express app.
Consider where and how you write the error middleware function.
You got /4 concepts.