Python programming language provides programmers a huge number of exception handler libraries that help them to handle different types of exceptions.
An exception is thrown when the code might go wrong and lead to an error. But when we explicitly want to raise an exception, we can do it by raising an exception with an explicit statement.
Program to illustrate raising user generated Exception in Python
Output:
Explanation:
In the above code, we have created a class AgeError that inherits exceptions for creating and throwing user generated exceptions. The exception is thrown when a user enters a value 0 or less otherwise normal flow of code goes on. The code checks for eligibility of a person to vote.
need an explanation for this answer? contact us directly to get an explanation for this answer