(no title)
huwigs | 15 years ago
`sys.excepthook` is how you can do that.
Without:
x = {}
def f():
print(x['foo'])
f()
# ...
Traceback (most recent call last):
File "stack.py", line 6, in <module>
f()
File "stack.py", line 4, in f
print(x['foo'])
KeyError: 'foo'
With: import sys
def short_err(exc_type, exc, tb):
sys.stderr.write("error: tracebacks too long\n")
sys.excepthook=short_err
x = {}
def f():
print(x['foo'])
f()
#...
error: tracebacks too long
So don't worry about catching exceptions if you're just printing errors.
gn|15 years ago
Awesome. Thank you kindly.
> error: tracebacks too long
I like your style.