General Notes

Exception Handling

  • Refers to the way a program detects and responds to such errors, allowing it to recover or terminate gracefully instead of crashing.
  • Exception: Unexpected event that interrupts the normal flow of a program
  • Uses
    • Prevents programs from crashing suddenly
    • Provides clear and user-friendly error messages
    • Makes software more stable and reliable
    • Manages common errors
  • Causes of exceptions
    • Programming errors - such as using uninitialized variables or making logical mistakes.
    • Hardware or device failures - like a disk read error, printer disconnection, or other hardware malfunctions.
    • Division by zero
    • File errors - when a file is missing, unreadable, or cannot be accessed.
    • Invalid input

Exception Handling Using try and except (Python)

Example: File Not Found

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

Multiple Exception

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.

File Handling with Exception Handling

PYTHON

Python can be executed directly in the browser.

Editor — Python
Output
No output yet.