Exceptions
• Runtime Errors are called Exceptions
• Exceptions are
1. divide by zero
2. array index out of bounds
3. out of memory or out of disk space
4. overflow
5. underflow etc..
• Eexceptions are categorized into two
1. Synchronous Exceptions
2. Asynchronous Exceptions
• Synchronous exceptions (like divide by zero, array index out of bound, etc.) can be
controlled by the program
• Asynchronous exceptions (like an interrupt from the keyboard, hardware malfunction,
disk failure) are beyond the control of the program.
• When an exception occurs in a program, the program must raise the exception. After that
program must handle the exception otherwise the program will be immediately terminated.
• If exceptions are not handled by programs, then error messages are generated..
Example:
num=int(input("enter numerator"))
den=int(input("enter denominator"))
quo=num/den
print(quo)
Output:
enter numerator1
enter denominator0
ERROR!
Traceback (most recent call last):
File "<string>", line 3, in <module>
ZeroDivisionError: division by zero