When running Py2.4, take advantage of new logging module feature that

gives less ugly/misleading exceptions in some cases.
Not part of the default build.
This commit is contained in:
mhammond%skippinet.com.au 2006-10-16 09:19:39 +00:00
Родитель a8b8af80f9
Коммит 2f555d2f39
1 изменённых файлов: 23 добавлений и 13 удалений

Просмотреть файл

@ -35,6 +35,7 @@
# #
# ***** END LICENSE BLOCK ***** # ***** END LICENSE BLOCK *****
import sys
from xpcom import xpcom_consts, _xpcom, client, nsError, logger from xpcom import xpcom_consts, _xpcom, client, nsError, logger
from xpcom import ServerException, COMException from xpcom import ServerException, COMException
import xpcom import xpcom
@ -283,6 +284,7 @@ class DefaultPolicy:
# considered 'normal' - however, we still write a debug log # considered 'normal' - however, we still write a debug log
# record to help track these otherwise silent exceptions. # record to help track these otherwise silent exceptions.
if sys.version_info < (2,4):
# Note that Python 2.3 does not allow an explicit exc_info tuple # Note that Python 2.3 does not allow an explicit exc_info tuple
# and passing 'True' will not work as there is no exception pending. # and passing 'True' will not work as there is no exception pending.
# Trick things! # Trick things!
@ -292,13 +294,21 @@ class DefaultPolicy:
except: except:
logger.debug("'%s' raised COM Exception %s", logger.debug("'%s' raised COM Exception %s",
func_name, exc_val, exc_info = 1) func_name, exc_val, exc_info = 1)
else:
logger.debug("'%s' raised COM Exception %s",
func_name, exc_val, exc_info=exc_info)
return exc_val.errno return exc_val.errno
# Unhandled exception - always print a warning and the traceback. # Unhandled exception - always print a warning and the traceback.
# As above, trick the logging module to handle Python 2.3 # As above, trick the logging module to handle Python 2.3
if sys.version_info < (2,4):
try: try:
raise exc_info[0], exc_info[1], exc_info[2] raise exc_info[0], exc_info[1], exc_info[2]
except: except:
logger.exception("Unhandled exception calling '%s'", func_name) logger.exception("Unhandled exception calling '%s'", func_name)
else:
logger.error("Unhandled exception calling '%s'", func_name,
exc_info=exc_info)
return nsError.NS_ERROR_FAILURE return nsError.NS_ERROR_FAILURE
# Called whenever an unhandled Python exception is detected as a result # Called whenever an unhandled Python exception is detected as a result