[Tutor] Exceptions and wotnot
Glen Wheeler
wheelege@hotmail.com
Thu, 21 Feb 2002 00:43:16 +1100
Thanks alot Andy W! I can't believe it was RTFM, after all that. I hope
that importing sys doesn't add too much to the standalone version of the
program - it's 5MB already! (2MB zipped)
Thanks again,
Glen
>
> The "sys" module has a reference to the last traceback, strangely enough
> called "last_traceback" ;)
> You might also want to look at the "traceback" module, as it does some
work
> for you.
>
> Example:
>
> >>> this_is_just_to_create_an_error
> Traceback (most recent call last):
> File "<pyshell#1>", line 1, in ?
> this_is_just_to_create_an_error
> NameError: name 'this_is_just_to_create_an_error' is not defined
> >>> import sys,traceback
> >>> tb=sys.last_traceback
> >>> tb_info=traceback.format_tb(tb)
> >>> print tb_info
> [' File "C:\\PYTHON22\\Tools\\idle\\PyShell.py", line 274, in runcode\n
> exec code in self.locals\n', ' File "<pyshell#1>", line 1, in ?\n
> this_is_just_to_create_an_error\n']
> >>> print ''.join(tb_info)
> File "C:\PYTHON22\Tools\idle\PyShell.py", line 274, in runcode
> exec code in self.locals
> File "<pyshell#1>", line 1, in ?
> this_is_just_to_create_an_error
>
> >>>
>
> HTH,
> Andy
>