Question
Write the syntax of exception handling in Python.
Solution
✔ Verified
The basic syntax of exception handling in Python uses the try, except, else, and finally blocks. Here's the general structure is -
try:
# Code that might raise an exception
except ExceptionType:
# Code to handle the exception
else:
# Code that runs if no exception occurs (optional)
finally:
# Code that always runs, whether an exception occurs or not (optional)
Click here to download practice questions on
Exception Handling in PythonMore Questions on Exception Handling in Python
Question 6
"Every syntax error is an exception but every exception cannot be a syntax error." Justify the statement.
View solution