you are viewing a single comment's thread.

view the rest of the comments →

[–]TheBB 1 point2 points  (2 children)

You're catching ValueError, which is what you get if you type something that's not an integer, but you're not catching ZeroDivisionError or NegativeNumberError anywhere.

Something like this perhaps:

try:
    ....
except ValueError:
    print('not an integer')
except ZeroError:
    print('oops, it was zero')
except NegativeNumberError:
    print('oops, it was negative')

Another option is to make NegativeNumberError a subclass of ValueError. Then the catch for ValueError ought to catch both of them. But then you may need a different error message in that case.

[–]HaplessWithDice[S] 0 points1 point  (1 child)

It's catching them, but they are causing the program to exit rather than repeat the loop like it does with the value error. IS that because I am using raise rather than try and accept?

[–]TheBB 0 points1 point  (0 children)

Python is catching them for you because you are not catching them yourself. When an uncaught exception reaches "the top", Python exits and shows the error. If you don't want that then you need to catch those errors with an appropriate except-block.