Python Error Handing
Python Error Handing
Python
Programming
Agenda
▰ Types of Errors
▰ Syntax Errors
▰ Runtime Error
▰ Logical Errors
There are several types of errors that can occur in Python. Each
type indicates a different kind of problem in the code, and
comprehending these error types is crucial in creating effective
Python applications.
3
Back to main
Syntax Errors:
4
Syntax Errors:
5
Runtime Errors:
6
1- Name Error <<< Runtime Error
7
2- Type Error <<< Runtime Error
8
3- Index Error <<< Runtime Error
9
that object. This can happen when you misspell the name of an attribute or method or when you try to access a
10
Logical Errors:
11
Logical Errors:
▰ def calculate_factorial(n):
12
Try Except Block in Python
13
Try Except Block in Python
try:
print(x)
except:
print("An exception occurred, x is not
defined")
try:
print(x)
except NameError:
print("Variable x is not defined")
except:
print("Something else went wrong") 14
Try Except else Block in Python
try:
print("Hello")
except:
print("Something went wrong")
else:
print("Nothing went wrong")
15