2020年1月29日 星期三

Python3 處理所有錯誤

General Error Handling

In the "general error handling" section above, it says to catch all exceptions, you use the following code:
Toggle line numbers
   1 import sys
   2 try:
   3   untrusted.execute()
   4 except: # catch *all* exceptions
   5   e = sys.exc_info()[0]
   6   write_to_page( "<p>Error: %s</p>" % e )
However, it originally was:

Toggle line numbers
   1 try:
   2   untrusted.execute()
   3 except Exception as e:
   4   write_to_page( "<p>Error: %s</p>" % str(e) )

沒有留言:

張貼留言