I love Flask's error catching. It's beautifully simple:
@app.errorhandler(404)
def pageNotFound(error):
return "page not found"
works like charm. But it doesn't work for the 500 error code. I want to catch Python errors when something goes wrong an exception is raised in the code. Is that possible?
I should note that if I explicitly call return abort(500)
in a view then the 500 errorhandler does work. So this is explicitly for when the Python code fails.
Is this possible?
Best Answer
What you have described is, by default, how Flask works. My assumption is that you are running in debug mode, and therefore exceptions are being shown to you in the debug screen. Make sure debug mode is off, then try again. Here is a comment directly from the code itself: