title: Tornado user input error catching
body: <p>I am working on a Tornado app.  It has CRUD functions in a file called api.py, and the relevant bits of that are show here:</p>
  
  <pre><code>class UserEditException(Exception):
      def __init__(self, msg):
          self.msg = msg
      def __str__(self):
          return self.msg
  
  def create_user(first_name, last_name, email, password, session = None):
  
    others_with_same_email = session.query(MyAppUser).filter(MyAppUser.email.like(email)).all()
    if others_with_same_email is not None:
      raise UserEditException('Already another account with that email address.')
  </code></pre>
  
  <p>This is called by app.py, which contains the actual Handlers, including for the page to Create a new User. The relevent bits of app.py are shown here:</p>
  
  <pre><code>import api
  
  class CreateUserHandler(BaseHandler):
    def get(self):
      self.render(
        local_templates + "/create_user.html",
        user_msg = 'Enter new user attributes, including an email address not already in use.',
      )
  
    def post(self):
      user_msg = '' #currently there are no problems found with inputs
      password = self.get_argument("password") 
      email = self.get_argument("email")
      first_name = self.get_argument("first_name",default=None)
      last_name = self.get_argument("last_name",default=None)
      if user_msg == '':
        try:
          new_user = api.create_user(first_name, last_name, email, password, agent_uuid = self.current_user)
        except api.UserEditException, err:
          user_msg = str(err)
        else:
          user_msg = 'The new user,'+new_user['first_name']+' '+new_user['last_name']+' ('+new_user['email']+') has been created successfully.'
  
      self.render(
        local_templates + "/create_user.html",
        first_name = first_name,
        last_name = last_name,
        email = email,
        user_msg = user_msg,
      )
  </code></pre>
  
  <p>When I enter an email that is already in use (i.e. intentionally trigger an error in user creation), I know that in api.py it is triggering the UserEditException, because the message 'Already another account with that email address.' is being written to the server.  Then the program crashes.  Instead I want the UserEditException caught, and the error message put into "user_msg", to be displayed to the web page.  Can you point what I might be doing wrong in trying to catch this kind of error?  Thanks.</p>