Last active
August 29, 2015 14:23
-
-
Save tawateer/c07b8cd542c4748ace88 to your computer and use it in GitHub Desktop.
tornado中捕获异常并传给client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
import tornado.ioloop | |
import tornado.web | |
import tornado.httpserver | |
def _Exception(func): | |
def _decorator(*args, **kwargs): | |
self = args[0] | |
try: | |
func(*args, **kwargs) | |
except Exception, e: | |
self.write("%s" % e) | |
return _decorator | |
class MainHandler(tornado.web.RequestHandler): | |
@_Exception | |
def get(self): | |
raise Exception("Exception: This is a test") | |
if __name__ == "__main__": | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
]) | |
application.listen(8888) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment