CONCEPTS
01Try and except blocks
02Catching specific exceptions
03The finally block
04The else block
05Raising exceptions (raise)
06Custom exceptions
SYNTAX_DEMO
Handling runtime errors safely
try:
result = 10 / 0
except ZeroDivisionError:
print("Error: Cannot divide by zero.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
else:
print("Division successful.")
finally:
print("Execution completed.")