title: Flask global exception handling
body: <p>How could one handle exceptions globally with Flask? I have found ways to use the following to handle custom db interactions:</p>
  
  <pre><code>try:
      sess.add(cat2)
      sess.commit()
  except sqlalchemy.exc.IntegrityError, exc:
      reason = exc.message
      if reason.endswith('is not unique'):
          print "%s already exists" % exc.params[0]
          sess.rollback()
  </code></pre>
  
  <p>The problem with <code>try</code>-<code>except</code> is I would have to run that on every aspect of my code. I can find better ways to do that for custom code. My question is directed more towards global catching and handling for:</p>
  
  <pre><code>apimanager.create_api(
      Model,
      collection_name="models",
      **base_writable_api_settings
  )
  </code></pre>
  
  <p>I have found that this <code>apimanager</code> accepts <code>validation_exceptions</code>: [<code>ValidationError</code>] but I have found no examples of this being used.</p>
  
  <p>I still would like a higher tier of handling that effects all db interactions with a simple concept of "If this error: show this, If another error: show something else" that just runs on all interactions/exceptions automatically without me including it on every <code>apimanager</code> (putting it in my <code>base_writable_api_settings</code> is fine I guess). (<code>IntegrityError</code>, <code>NameError</code>, <code>DataError</code>, <code>DatabaseError</code>, etc)</p>