Re: an idea: "letter bombs"

Jaap Vermeulen (jaap@sequent.com)
Thu, 16 Dec 93 17:01:00 PST

| useful. What's more, Jaap's boilerplate is only 23 lines long, so it isn't
| too great a trial to have to hand-include something like it in every
program
| I ever write.

I didn't include the stacktrace procedure. I added it at the end of this
message just in case...

In a previous message I was talking about KeyboardInterrupt. The only reason
I *have* to catch it, is because it prints a stacktrace. Soooo, here is at
least one exception where it is an absolute pain in the behind to have a
stacktrace in an end user program.

However, I would hate to see all kinds of special cases depending on the
type of exception etc. etc. And except for the KeyboardInterrupt, which is
unpredictable, most other exceptions are predictable and therefore easier to
catch and convert to something you like.

-Jaap-

------- Function Stacktrace

def StackTrace(tb):
import os

if tb: last_file = StackTrace(tb.tb_next)
else: return

file = tb.tb_frame.f_code.co_filename
line = tb.tb_frame.f_lineno

if file != last_file:
if file[-3:] == '.py':
module = os.path.split(file)[1][:-3]
sys.stderr.write('\n Module ' + `module`)
else:
sys.stderr.write('\n File ' + `file`)
sys.stderr.write(': line ' + `line`)
else:
sys.stderr.write(', line ' + `line`)
return file