Exception Handling in Python in Python
Updated on May 31, 2025 | By Learnzy Academy
Exception Handling is used to manage errors during program execution without crashing the program.
Common Keywords:
- try – Block to test for errors.
- except – Block to handle the error.
- else – Runs if no error occurs.
- finally – Always runs, error or not.
Example:-
try:
x = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero.")
else:
print("Division successful.")
finally:
print("Execution complete.")
Output:--
Cannot divide by zero.
Execution complete.
Click here to download practice questions on
Exception Handling in PythonList of question on "Exception Handling in Python"
- What is the purpose of the else block in exception handling?
- What is the use of raise in Python?
- How can you catch multiple exceptions in one block?
- What is the use of the finally block?
- Write the syntax of exception handling in Python.
- Name any four common exceptions in Python.
- "Every syntax error is an exception but every exception cannot be a syntax error." Justify the statement.