I find the instruction exercises hard to follow and particularly when it mention a code word not taught yet such as “raise”. I am going thru Python Control Flow. At the section for code words “try” and “except”, the instruction is not only hard to understand also it mentions a code word “raise” which shows up for the first time. Frustrating trying to solve the problem without referring to hint or the solution.
As far as I know, the
raise keyword forces the compiler to throw an error, regardless of whether an actual error occurred.
From the documentation:
This also might be helpful:
Raise is used to make/bring up an error. I hope this helps you
It raises an error…
If you didn’t want something to happen, or maybe you want a fail-safe in place just in case an error occurs, you would use
Here is an example:
if num != 5: raise ValueError
or you could do
try: print(2 / 0) except ZeroDivisionError: print('You caused an error...')