Exception Handling
Exception Handling
An exception is a runtime error that occurs while your program is running, causing it to crash. Exception handling uses try, except, else, and finally blocks to catch these errors gracefully so your program can deal with them instead of stopping abruptly.
Common Error Types:
ValueError: Raised when a function gets an argument of the right type but inappropriate value (e.g., trying to convert "hello" into an integer).
ZeroDivisionError: Raised when you try to divide a number by zero.
KeyError: Raised when you try to look up a dictionary key that doesn't exist.
TypeError: Raised when an operation is applied to an object of an inappropriate type.