存储引发异常时由异常创建的对象Python
这是我的特例课存储引发异常时由异常创建的对象Python,python,exception,Python,Exception,这是我的特例课 class SampleError(Exception): def __init__(self): self.history = Stack() 这是函数 def f(x): raise SampleError 运行f(x)时,如何存储在引发SampleError时创建的堆栈 一如既往地谢谢你 看看这个模块。它将使您能够从任何实例生成回溯。经过一些后期处理后,您还可以以任何形式存储。只需查看模块即可。它将使您能够从任何实例生成回溯。经过一些后期
class SampleError(Exception):
def __init__(self):
self.history = Stack()
这是函数
def f(x):
raise SampleError
运行f(x)时,如何存储在引发SampleError时创建的堆栈
一如既往地谢谢你 看看这个模块。它将使您能够从任何实例生成回溯。经过一些后期处理后,您还可以以任何形式存储。只需查看模块即可。它将使您能够从任何实例生成回溯。经过一些后期处理后,您还可以以任何形式存储。如果“存储”是指分配给变量进行分析,请使用:
请注意规范中有关循环引用的警告。如果“存储”是指分配给变量进行分析,请使用:
请注意规范中关于循环引用的警告。也许您正试图这样做 导入回溯
class SampleError(Exception):
def __init__(self):
self.history = traceback.extract_stack()
def f(x):
raise SampleError
try:
f(5);
except SampleError, e:
print e.history
out = traceback.format_list(e.history)
print out[0]
也许你想做这样的事 导入回溯
class SampleError(Exception):
def __init__(self):
self.history = traceback.extract_stack()
def f(x):
raise SampleError
try:
f(5);
except SampleError, e:
print e.history
out = traceback.format_list(e.history)
print out[0]
如果您只想访问异常属性:
try:
f()
except SampleError, error:
history = error.history
如果您只想访问异常属性:
try:
f()
except SampleError, error:
history = error.history
你说的“存储”是指变为变量吗?你说的“存储”是指变为变量吗?