Raise Exception | SoloLearn: Learn to code for FREE!


Raise Exception

Can anyone please tell me what is Raise exception for? I have read comments on the Raise exception lesson but didn't catch that

4/3/2019 12:10:54 PM

Mahdi Jafari

2 Answers

New Answer


Raise exception, means to cause your program's execution to stop with an error message in a specific event. For example you can raise a ValueError when you asked for user input and you got something that won't work for your program, like you need a positive number and you got zero. It can also be used as a control flow tool, when you "catch" the exception in a try/expect block and manipulate what should happen in the program when the error is raised. With previous example you can expect the same error you raised before and give a default value instead of the faulty user input.


Tibor Santa Great explanation, TY