Exception Handling Note_2025-26
Exception Handling Note_2025-26
An exception is defined as an unexpected condition in a program that causes the program’s flow to be
interrupted.When the Python interpreter attempts to execute invalid code, it throws an exception, and if
the exception is not handled, it disturbs the regular flow of the program’s instructions and outputs a
traceback. Exceptions are a form of error in which the code has the correct syntax but contains a fault.
There are many different types of exceptions, but some of the most prevalent are: ImportError,
ZeroDivisionError, NameError, and TypeError.
2.Explain the different types of built-in exceptions.
Ans Built-in Exceptions Commonly occurring exceptions are usually defined in the compiler/interpreter.
These are called built-in exceptions. Python’s standard library is an extensive collection of built-in
exceptions that deals with the commonly occurring errors (exceptions) by providing the standardized
solutions for such errors. On the occurrence of any built-in exception, the appropriate exception handler
code is executed which displays the reason along with the raised exception name. The programmer then
has to take appropriate action to handle it.
Name of Built-in- Explanation
Exceptions
SyntaxError It is raised when there is an error in the syntax of the Python code
ValueError It is raised when a built-in method or operation receives an argument
that has the right data type but mismatched or inappropriate values
IOError It is raised when the file specified in a program statement cannot be opened.
KeyboardInterrupt It is raised when the user accidentally hits the Delete or Esc key
while executing a program due to which the normal flow of the
program is interrupted