Global Exception Handling in Google App Engine

坚强是说给别人听的谎言 提交于 2019-12-01 00:50:39

If you're using the webapp framework, you should already be defining a subclass of RequestHandler that serves as a base class, with all your app's handlers extending that. You can simply override handle_exception, which serves as a global exception handler for any uncaught exceptions.

The default implementation calls self.error(500), logs the exception, and if debug is on, outputs a stacktrace.

If you're using another framework, you could write a piece of WSGI middleware that calls the wrapped WSGI app, and catches any thrown exceptions, dealing with them as you wish.

Well, at the most basic level you could wrap all of your handler scripts referenced by app.yaml in a giant try-except block.

If you are using the webapp framework, consider overriding handle_exception() for each of your request handlers. If you want all of your request handlers to have some basic exception handling that you specify, you could a request handler which implements this method and then derive all of your handlers from it.

You application probably has a main() function, put the try/except in that function, and it'll catch everything from your application.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!