Try-Except Blocks
Basic exception handling
Interview Relevant: Error handling
Try-Except
Handle errors gracefully.
Code Examples
python
1try:
2 result = 10 / 0
3except ZeroDivisionError:
4 print("Cannot divide by zero!")
5except Exception as e:
6 print(f"Something else happened: {e}")