[wingide-users] A few observations on 2.0 rc1
Chuck Esterbrook
ChuckEsterbrook at yahoo.com
Mon Oct 18 02:22:18 EDT 2004
On Mon, 18 Oct 2004 07:51:39 +0200, F. GEIGER wrote:
> Now I know that I have to catch a ValueError in my program.
>
>
> The same happens with uncaught exceptions. I cannot see their class
> in the Exception Window.
>
> Any thoughts?
The WingIDE guys probably just forgot to include it. Python is very strange in that if you convert an exception to a string, it doesn't tell you what exception type was thrown! So, for example, this is not sufficient:
try:
foo()
except Exception, e:
print 'Caught exception: %s' % e
Instead, it needs to be:
print 'Caught exception: %s: %s' % (e.__class__.__name__, e)
Feels like an oversight in the design of exceptions in my opinion, but it's the way that it is. I even have a function for it:
def excstr(e):
"""
Return a readable string for an exception. Format is:
Class: message
As in:
KeyError: quoteSymbol
AssertionError: quote={}
"""
if not e:
return None
else:
return '%s: %s' % (e.__class__.__name__, e)
-Chuck
More information about the wingide-users
mailing list