@app.route('/')
def index():
    raise Exception("Can't connect to database")

@app.errorhandler(Exception)
def exception_handler(error):
    return '!!!!' + repr(error)
Catching a 500 server error in Flask