[Tutor] please return flys in ointment
Jim Mooney
cybervigilante at gmail.com
Mon Jul 8 22:18:23 CEST 2013
On 8 July 2013 12:47, Dave Angel <davea at davea.name> wrote:
> To make a custom error, first pick another error that's a superset of what
> you're doing. Then simply derive your error class from it. As a minimum:
>
> class TooHugeError (ValueError):
> pass
Hmm, I tried that, but instead of going to the exception for too huge:
except TooHugeError as err: , which prints a "too big" statement, it
went to a valid exception I already had for a Value Error: except
ValueError as err:, and printed the error as a simple Value Error
rather than my own statement. i.e.
try:
blah, blah, blah...
if len(numbers_str) > 36: raise TooHugeError
break
except KeyboardInterrupt:
print('Program cancelled by user')
sys.exit()
except ValueError as err: # I go here
print(original, "is not an integer.")
continue
except TooHugeError as err: # when I want to go here
print(original, "is too big.\n999...decillion is max:"
" 10**37-1 or 36 chars or 12 groups of 3 chars")
BTW, to fit in their new, enormous sidebar ad, gmail is shrinking my
text box so small things are gapping and overlapping, so if something
looks funny, it was okay in my IDE, which I've cut to about 70 width
for mail readers ;')
Jim
More information about the Tutor
mailing list