Printing exceptions

Aahz Maruch aahz at netcom.com
Mon Jun 12 17:17:42 EDT 2000


In article <8i2p3i$3pd$1 at nnrp1.deja.com>, Arinté  <jamarijr at my-deja.com> wrote:
>My embedded python app sets an exception string, python can easily
>print this error using
>print sys.exc_value
>but, when I try to post it in my MessageBox
>pos.alert(sys.exc_value)
>the application crashes, I even tried putting the failing part in a
>try..catch block and it still crashed (What the...)
>Of course
>pos.alert("testing this messagebox") works fine

Do you get any kind of error message when your application crashes?

I'm suspecting this probably has something to do with the slightly weird
reference counting with exceptions.  In addition, you're supposed to use
sys.exc_info() because it's thread-safe.

Here's some code that will extract a safe string from the exception that
you should then be able to pass into your MessageBox:

import sys, traceback
try:
  ....
except:
  s = apply ( traceback.format_exception, sys.exc_info() )
  pos.alert(s)
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"I love you."
"Duhhhh!"  --SFJ



More information about the Python-list mailing list