如何获取导致异常的函数的参数

时间:2013-03-06 15:11:23

标签: 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


@myDecorator
def do_something(self):
  do_something_again("Some text")

我的问题是:如何在“except”块中显示赋予函数“do_something_again”的参数?

1 个答案:

答案 0 :(得分: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