What is exception-
-An exception is an event which occurs during the execution of a program that break the normal flow of the program's instructions.
Exception handling-
- We can handle exception in python by try and except block.
- Try block is a block in which we write that part of program where chances of exception will occur.
- Except is a part where we handle the generated exceptions or this block is run after the exception generate.
Keywords that are used in exception handling is-
- try
- except
- finially
- raise
Most common error-
- ZeroDivisionError: Occurs when any thing is divided by zero.
- NameError: It occurs when a variable name is not found. It may be local or global.
- IndentationError: if incorrect indentation, python support indentation.
- IOError: When input output task is fails then this error occur.
- EOFError: It occurs when the end of the file is reached, and yet operations are being performed.
- IndexError : when task is perform at out of index range.
-ZeroDivisionError
program-
try:
n=1/0
except ZeroDivisionError:
print("Number is divide by 0")
Number is divide by 0
l=[1,2,3,4]
try:
print(l[10])
except IndexError:
print("List is out of range")
List is out of range