Sujet : Re: how to discover what values produced an exception?
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 04. May 2024, 16:15:02
Autres entêtes
Organisation : Stefan Ram
Message-ID : <method-20240504145813@ram.dialup.fu-berlin.de>
References : 1 2
ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
Sometimes you really need those values. If they're values of global
names, you can kind of get them in the IDLE shell up to a point.
The way I see it, the issue here isn't just on Python,
the language - it's also on us, the coders! I mean, when
I define my own function, I can roll with something like:
def function( value ):
if value > 0:
return log( value )
else:
raise ZeroDivisionError( 'domain error' )
print( function( -1 ))
. Or I can go with something like this:
def function( value ):
if value > 0:
return log( value )
else:
message = 'domain error: '
message += '\nThe argument value was: '+ repr( value ) + '.'
message += '\nbut a value > 0 was expected.'
raise ZeroDivisionError( message )
print( function( -1 ))
. And you know what? The second option's gonna give you this output:
ZeroDivisionError: math domain error:
The argument value was: -1.
but a value > 0 was expected.
.