Custom Exception in Python
Concept
When an error occurs, or exception as we call it, Python will normally stop and generate an error message
But this is not expected in Real Life Application, So these exceptions can be handled using the try, except
statement.
Code
Example 1:
x = 10
if x == 10:
raise ValueError
elif x == 20:
raise KeyboardInterrupt
elif x == 30:
raise Exception("My Choice")
else:
print("All Okay")
Output:
Traceback (most recent call last): File "./prog.py", line 4, in ValueError
Comments
Post a Comment