title: How to handle general exception in flask at single place?
body: <p>I am using <code>flask</code>, here giving example, what I want to do. I copied code from flask portal.</p>
  
  <pre><code>from flask import Flask
  app = Flask(__name__)
  
  @app.route('/')
  def hello_world():
      return 'Hello, World!'
  </code></pre>
  
  <p>Running the app</p>
  
  <pre><code>(py35) root@localhost:tmp root$ flask run
   * Serving Flask app "hello"
   * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
  </code></pre>
  
  <p>Send request</p>
  
  <pre><code>root@localhost:~ root$ curl http://localhost:5000/
  Hello, World!
  </code></pre>
  
  <p>I modify my function and change it to raise error.</p>
  
  <pre><code>@app.route('/')
      def hello_world():
          print(xyz)
          return 'Hello, World!'
  </code></pre>
  
  <p>When i try to send request, it failed </p>
  
  <pre><code>[2017-11-06 10:22:13,625] ERROR in app: Exception on / [GET]
  Traceback (most recent call last):
    File "/py35/lib/python3.5/site-packages/flask/app.py", line 1982, in wsgi_app
      response = self.full_dispatch_request()
    File "/py35/lib/python3.5/site-packages/flask/app.py", line 1614, in full_dispatch_request
      rv = self.handle_user_exception(e)
    File "/py35/lib/python3.5/site-packages/flask/app.py", line 1517, in handle_user_exception
      reraise(exc_type, exc_value, tb)
    File "/Users/nile2691/sbdev/StorageCenterUI/.tox/py35/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
      raise value
    File "/py35/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
      rv = self.dispatch_request()
    File "py35/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
      return self.view_functions[rule.endpoint](**req.view_args)
    File "/private/tmp/hello.py", line 6, in hello_world
      print(xyz)
  NameError: name 'xyz' is not defined
  </code></pre>
  
  <p>I have can add <code>try...except</code> in my code, but in real code, its in many place, and I dont want to handle this general exception everywhere.</p>
  
  <p>Is there any way like </p>
  
  <pre><code>try:
      process_flask_request()
  except Exception as ex:
      # Log detail exception
      logger.exception(ex)
      return "Custome error message for all general exception"
  </code></pre>
  
  <p>With this changes, instead of getting general error like below</p>
  
  <pre><code>curl http://localhost:5000/
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"&gt;
  &lt;title&gt;500 Internal Server Error&lt;/title&gt;
  &lt;h1&gt;Internal Server Error&lt;/h1&gt;
  &lt;p&gt;The server encountered an internal error and was unable to complete your request.  Either the server is overloaded or there is an error in the application.&lt;/p&gt;
  </code></pre>
  
  <p>I want to return proper output, with custom error message.</p>