Revision 433
Added by Aaron Marcuse-Kubitza almost 13 years ago
exc.py | ||
---|---|---|
1 | 1 |
# Exception handling |
2 | 2 |
|
3 |
import atexit |
|
3 | 4 |
import sys |
4 | 5 |
|
5 | 6 |
import strings |
... | ... | |
18 | 19 |
msg = strings.ensure_newl(str(e)) |
19 | 20 |
if with_name: msg = util.type_name(e)+': '+msg |
20 | 21 |
sys.stderr.write('! '+msg) |
22 |
|
|
23 |
class ExTracker: |
|
24 |
def __init__(self): |
|
25 |
self.e_ct = 0 |
|
26 |
def at_exit(): |
|
27 |
if self.e_ct > 0: |
|
28 |
raise SystemExit('Encountered '+str(self.e_ct)+' error(s)') |
|
29 |
atexit.register(at_exit) |
|
30 |
|
|
31 |
def track(self, e, **format): |
|
32 |
self.e_ct += 1 |
|
33 |
print_ex(e, **format) |
Also available in: Unified diff
exc.py: Added ExTracker to track printed (suppressed) Exceptions and exit with nonzero status if any were encountered