2013-03-06 39 views
0

可以说,我下面的代码:如何获取引起异常的函数的参数

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") 

我的问题是:我怎样才能显示它是考虑到功能“do_something_again”我里面“的说法除了“块?

回答

0

打印str(e)获取附加信息。示例在您的情况下:

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 
+0

这将打印异常名称,而不是“某些文本” – vigri 2013-03-06 16:17:04