2013-03-06 31 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