Recall & Review
beginner
What is the purpose of error handler decorators in Flask?
Error handler decorators in Flask let you define functions that run automatically when specific errors happen. They help you show friendly messages or handle problems smoothly.Click to reveal answer
beginner
How do you use the @app.errorhandler decorator in Flask?
You put @app.errorhandler(error_code) above a function. This function will run when that error happens. For example, @app.errorhandler(404) runs when a page is not found.
Click to reveal answer
intermediate
What does the function decorated with @app.errorhandler receive as input?
The function receives the error object that caused the problem. You can use it to get details about the error and decide what to show the user.
Click to reveal answer
intermediate
Can you handle multiple error codes with one error handler decorator in Flask?
No, you cannot handle multiple error codes with one @app.errorhandler by passing a tuple like (404, 500). You need to define separate functions for each error code or use base exception classes for broader coverage.
Click to reveal answer
intermediate
What is the benefit of using error handler decorators instead of try-except blocks in Flask routes?
Error handler decorators keep your route code clean and separate error handling logic. They automatically catch errors app-wide, so you don't repeat try-except in every route.
Click to reveal answer
What does @app.errorhandler(404) do in a Flask app?
✗ Incorrect
The decorator @app.errorhandler(404) runs the decorated function when a 404 Not Found error occurs.
What argument does the function decorated with @app.errorhandler receive?
✗ Incorrect
The error handler function receives the error object that triggered the error.
Can one @app.errorhandler decorator handle multiple error codes?
✗ Incorrect
@app.errorhandler handles one error code or exception type per decorated function. To handle multiple errors, define multiple handlers.
Why use error handler decorators instead of try-except in routes?
✗ Incorrect
Error handler decorators separate error logic and apply globally, keeping routes simpler.
Which of these is a correct way to define a 500 error handler in Flask?
✗ Incorrect
Option A correctly uses @app.errorhandler with integer 500 and defines a function with error argument.
Explain how to create a custom error page for a 404 error using Flask error handler decorators.
Think about how to catch the 404 error and show a friendly page.
You got /3 concepts.
Describe the advantages of using error handler decorators in a Flask web application.
Consider how error handling affects code organization and user feedback.
You got /4 concepts.