2013-01-07 52 views
-1

我目前使用下面的代碼:如何獲取異常消息?

from google.appengine.api.urlfetch import Error 
try: 
    # some code here 
except Error, message: 
    logging.error('exception - %s' % message) 

但它只會捕捉網址抓取錯誤。 如果我將其替換爲:

try: 
    # some code here 
except: 
    logging.error('exception') 

然後它捕獲所有錯誤。但是在這種情況下我怎麼能得到錯誤信息呢?

回答

1

趕上通用Python異常:

try: 
    i = 6/0 
except Exception as e: 
    print(e)