There are two similar handlers: AgeHandler1 and AgeHandler2. In the first one we simply raise a specific exception to return an error message, in the second - we manually return
In general the best approach is to override RequestHandler.write_error
. This is similar to your first approach, but you don't need the try/except in the body of the handler because Tornado will handle this for you.
Explicit tests like those in your second example are also good, but it's impractical to catch all possible errors this way so you'll always need something to handle uncaught exceptions.