Khushi G. answered 02/07/24
Unlock Your Potential with Engaging Learning!
Exception handling is a mechanism used to deal with runtime errors, known as exceptions.
Exceptions can occur for various reasons, such as division by zero, trying to open a file that does not exist. (file not found error).
In Python, you achieve exception handling using the try, except , else , and finally blocks.
try :- This enclose the block of code that might raise an exception.
except :- If any error is raised in try block then except block handles that error.
else :- If no error is raised then control will go to else block.
finally :- This block is executed regardless of whether an exception occurs or not.