Python 如何获取导致异常的函数的参数
假设我使用以下代码:Python 如何获取导致异常的函数的参数,python,exception,Python,Exception,假设我使用以下代码: def myDecorator(func): def wrapper(self): try: func(self) except Exception as e: print "The argument of the function was:" # print "Some Text" raise wrapper.__name__ = funct.__name__ return wrapper @myDeco
def myDecorator(func):
def wrapper(self):
try:
func(self)
except Exception as e:
print "The argument of the function was:" # print "Some Text"
raise
wrapper.__name__ = funct.__name__
return wrapper
@myDecorator
def do_something(self):
do_something_again("Some text")
我的问题是:如何在我的“除”块?Printstr(e)
中显示函数“do\u something\u”的参数以获取附加信息。你的例子是:
def myDecorator(func):
def wrapper(self):
try:
func(self)
except Exception as e:
print "The argument of the function was:", str(e)
raise
wrapper.__name__ = funct.__name__
return wrapper
这将打印异常名称,而不是“某些文本”