[Tutor] Exceptions and wotnot

Andy W toodles@yifan.net
Wed, 20 Feb 2002 22:05:49 +0800


>   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

No worries. I never say RTFM ;)
Sorry if I misled you by using last_traceback rather than exc_traceback (see
Arcege's email). Thanks for correcting me Arcege, I wasn't paying enough
attention to what I was doing, and wasn't using the try-except as was used
in the original.

Andy

>
>
> >
> > 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
> >
>
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>