Exception class:
- “Exception” is pre-defined class.
- “Exception” is the Parent class of all other exception classes.
- Instead of handling multiple exceptions with number of except blocks, we can specify “Exception” type to handle all.
- We need to provide the common the error information to handle using “Exception” class.
Note: We can display the message of Exception object by collecting into variable in “except” block.
class Division:
def main():
try:
print("Enter 2 numbers :")
x = int(input())
y = int(input())
z = x/y
print("Result :",z)
except Exception as msg:
print("Exception :",msg)
return
Division.main()