Junior — Middle
What types of exception handling blocks do you know in programming languages?
sobes.tech AI
Answer from AI
In Python, exception handling uses the following blocks:
try— contains code that may raise an exception.except— block for handling specific or all exceptions.else— executes if no exceptions occurred.finally— always executes, regardless of exceptions, usually for resource cleanup.
Example:
try:
result = 10 / 0
except ZeroDivisionError:
print("Division by zero is not possible")
else:
print("Result", result)
finally:
print("End of processing")
Thus, these blocks allow flexible error management and ensure proper termination of operations.