Chapter First 2ggg
Chapter First 2ggg
e r
t ion
p
a pt g
h
C xce lin
E a nd
H
Exceptions :- Exceptions are errors that get
triggered automatically or forcefully
(By the programmer).Errors can be
syntax errors, logical errors or run
time error which results in
unexpected outputs.
Syntax errors or Of a particular
parsing errors :- programming of the program
This type of error language. When a until we correct ,
occurs when user syntax error save and rerun the
have not followed occurs, interpreter program .
the rules stops execution
1. Shell mode :- when a syntax error is 2. Script mode:- During script mode error
encountered python gives a small a dialog box specifying the name of the
description about the error and a suggestion error and a small description about the error
to rectify it. is displayed.
Exceptions:-
An exception is a Python
object that represents an
error. When an error occurs
during the execution of a
program, an exception is said
to have been raised. Such an
exception needs to be
handled by the programmer
so that it does not terminate
the programs abnormally.
Exceptions
Built in
User defined Exceptions
Exceptions
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.
KeyboardInterrup It is raised when the user accidentally hits the Delete or Esc key while
t executing a program due to which the normal flow of the program is
interrupted.
ImportError It is raised when the requested module definition is not found
EOFError It is raised when the end of file condition is reached without reading any data
by input().
ZeroDivisionErro It is raised when the denominator in a division operation is zero
r
IndexError It is raised when the index or subscript in a sequence is out of range
Commonly occurring Built -in exceptions in Python are
NameError It is raised when a local or global variable name is not defined..
TypeError It is raised when an operator is supplied with a value of incorrect data type.
OverFlowError It is raised when the result of a calculation exceeds the maximum limit for
numeric data type.