0

I don't see the point in the raise statement. Can someone please explain the raise statement to me?

13th Sep 2016, 2:16 PM
DELETED
2 Réponses
+ 3
here is sample example: def super(x): if type(x) != int: raise TypeError("integer is required but given %s " % (type(x)) print(x) Usage: >>> super(2.0) output: Traceback .......... TypeError:integer is required but given float
16th Sep 2016, 3:21 AM
Sagar Pohekar
+ 2
Sometimes you want to define your own exceptions to get more flexibility in determining what failed and at what part of the program. And well... There's no other way to raise them except using `raise`. A lot of libraries come with their own set of exceptions to help you understand what exactly gone wrong under the hood (they're named like MysqlOperationError, MysqlProgrammingError etc). And they're all raised with `raise`. :)
13th Sep 2016, 10:33 PM
trueneu
trueneu - avatar