Flask and sys.excepthook Flask and sys.excepthook flask flask

Flask and sys.excepthook


Flask already handles exceptions in views for you. Using sys.excepthook is not the right way to handle this, the hook will never be called.

Specify a custom exception handler with Flask instead, see the Redirects and Errors section of the Quickstart manual:

from flask import render_template@app.errorhandler(500)def page_not_found(error):    return 'some error message'

Flask also uses the logging module to record exceptions; configure the logging module to write anything of severity logging.ERROR to the console or a log file.

Since you use app.run(debug=True, port=5001), you'll already see exceptions printed to the console.

Note that the 500 error page is only ever invoked when debug is not set to True however; otherwise the Werkzeug debug view is invoked instead.