0% found this document useful (0 votes)
21 views9 pages

Chapter First 2ggg

Exceptions in Python represent errors that occur during program execution and need to be handled to prevent abnormal termination; there are user-defined exceptions created by programmers as well as built-in exceptions for commonly occurring errors like syntax errors, division by zero, and incorrect data types; built-in exceptions trigger the appropriate exception handler code while user-defined exceptions inherit from built-in exceptions and can be customized for specific needs.

Uploaded by

CS LAB
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views9 pages

Chapter First 2ggg

Exceptions in Python represent errors that occur during program execution and need to be handled to prevent abnormal termination; there are user-defined exceptions created by programmers as well as built-in exceptions for commonly occurring errors like syntax errors, division by zero, and incorrect data types; built-in exceptions trigger the appropriate exception handler code while user-defined exceptions inherit from built-in exceptions and can be customized for specific needs.

Uploaded by

CS LAB
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

- 1

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

Not follow the rules


Program in python :-
>>>marks=10
>>>if marks>10 :
print “good marks” Syntax error parenthesis missing in call to print
There are two types of modes for running python program one is

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

User defined Exceptions:-When a programmer/user create exceptions


as per his own needs. These are useful in case of inheritance when
user drive his own exception from built- in exception.
Built in Exceptions:- Commonly occurring exceptions are usually
defined in the compiler/interpreter. These are called built-in exceptions

executed which displays


On the occurrence of any the reason along with the
built-in exception, the raised exception name.
appropriate exception The programmer then has
handler code is to take appropriate action
to handle it
Commonly occurring Built -in exceptions in Python are
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.

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..

IndentationError It is raised due to incorrect indentation in the program code.

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.

You might also like