SlideShare a Scribd company logo
Exception Handling
Errors and Exceptions
 Python Errors and Built-in Exceptions: Python
(interpreter) raises exceptions when it
encounters errors.
 When writing a program, we, more often than
not, will encounter errors.
 Error caused by not following the proper
structure (syntax) of the language is called
syntax error or parsing error
 An exception in Python is an incident that happens
while executing a program that causes the regular
course of the program's commands to be disrupted.
 When a Python code comes across a condition it
can't handle, it raises an exception.
 An object in Python that describes an error is
called an exception.
Exceptions versus Syntax Errors
LECT 29- EXCEPTION HANDLING.pptx      b.
 ZeroDivisionError: ZeroDivisionError in Python
indicates that the second argument used in a division
(or modulo) operation was zero.
 OverflowError: OverflowError in Python indicates
that an arithmetic operation has exceeded the limits
of the current Python runtime. This is typically due to
excessively large float values, as integer values that
are too big will opt to raise memory errors instead.
 ImportError: It is raised when you try to import a
module which does not exist. This may happen if you
made a typing mistake in the module name or the
module doesn't exist in its standard path..
 IndexError: An IndexError exception is raised when
you refer a sequence which is out of range. In the
example below, the list abc contains only 3 entries,
but the 4th index is being accessed, which will result
an IndexError exception.
 TypeError: When two unrelated type of objects are
combined, TypeErrorexception is raised.
 IndentationError: Causes due to Unexpected
indent.
 Syntax errors: These are the most basic type of
error. They arise when the Python parser is unable to
understand a line of code. Syntax errors are almost
always fatal, i.e. there is almost never a way to
successfully execute a piece of code containing
syntax errors.
 Run-time error: A run-time error happens when
Python understands what you are saying, but runs
into trouble when following your instructions
 Key Error : Python raises a KeyError whenever a
dict() object is requested (using the format a =
adict[key]) and the key is not in the dictionary.
 Value Error: In Python, a value is the information that
is stored within a certain object. To encounter a
ValueError in Python means that is a problem with the
content of the object you tried to assign the value to.
 Python has many built-in exceptions:
 Python uses try and except keywords to handle
exceptions. Both keywords are followed by
indented blocks
 The things we need to observe are:
1. You should be able to understand the mistakes;
the error might be done by user, DB connection
or server.
2. Whenever there is an error execution should not
stop. Ex: Banking Transaction
3. The aim is execution should not stop even
though an error occurs
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
 A try statement can have more than one except
clause, to specify handlers for different
exceptions.
 Note that at most one handler will be executed.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.
LECT 29- EXCEPTION HANDLING.pptx      b.

More Related Content

Similar to LECT 29- EXCEPTION HANDLING.pptx b. (20)

PPTX
Exception Handling in Python Programming.pptx
vinayagrawal71
 
PPTX
Download Wondershare Filmora Crack Latest 2025
hyderik195
 
PPTX
Adobe Photoshop 2025 Cracked Latest Version
hyderik195
 
PPTX
FL Studio Producer Edition Crack 24 + Latest Version [2025]
hyderik195
 
PPTX
Exception Handling in python programming.pptx
shririshsri
 
PPTX
Python Unit II.pptx
sarthakgithub
 
PPTX
Python Exception Handling (Python Course)
IGustiNyomanAntonSur
 
PDF
Exception handling3.pdf
Brokeass1
 
PPTX
Python for beginners textbook slides ppt
AnithaChristyAngelin
 
PPTX
Mastering Errors and Exceptions in Python: A Comprehensive Guide
Vignan's Foundation for Science, Technology & Research (Deemed to be University)
 
PDF
Wondershare UniConverter Crack FREE Download 2025 version
mu394968
 
PPTX
Exception Handling.pptx
Pavan326406
 
PPTX
Exception Handling in Python topic .pptx
mitu4846t
 
PDF
Exception handling in python
Lifna C.S
 
PPTX
Python Session - 6
AnirudhaGaikwad4
 
PPTX
Exception handling.pptx
NISHASOMSCS113
 
PPTX
Python Exceptions Powerpoint Presentation
mitchellblack733
 
PPT
Firoze_Errors_Exceptions in python__.ppt
urstrulysurya
 
PPTX
Error and exception in python
junnubabu
 
Exception Handling in Python Programming.pptx
vinayagrawal71
 
Download Wondershare Filmora Crack Latest 2025
hyderik195
 
Adobe Photoshop 2025 Cracked Latest Version
hyderik195
 
FL Studio Producer Edition Crack 24 + Latest Version [2025]
hyderik195
 
Exception Handling in python programming.pptx
shririshsri
 
Python Unit II.pptx
sarthakgithub
 
Python Exception Handling (Python Course)
IGustiNyomanAntonSur
 
Exception handling3.pdf
Brokeass1
 
Python for beginners textbook slides ppt
AnithaChristyAngelin
 
Mastering Errors and Exceptions in Python: A Comprehensive Guide
Vignan's Foundation for Science, Technology & Research (Deemed to be University)
 
Wondershare UniConverter Crack FREE Download 2025 version
mu394968
 
Exception Handling.pptx
Pavan326406
 
Exception Handling in Python topic .pptx
mitu4846t
 
Exception handling in python
Lifna C.S
 
Python Session - 6
AnirudhaGaikwad4
 
Exception handling.pptx
NISHASOMSCS113
 
Python Exceptions Powerpoint Presentation
mitchellblack733
 
Firoze_Errors_Exceptions in python__.ppt
urstrulysurya
 
Error and exception in python
junnubabu
 

Recently uploaded (20)

PDF
OPPOTUS - Malaysias on Malaysia 1Q2025.pdf
Oppotus
 
PDF
Web Scraping with Google Gemini 2.0 .pdf
Tamanna
 
PDF
Merits and Demerits of DBMS over File System & 3-Tier Architecture in DBMS
MD RIZWAN MOLLA
 
PDF
How to Connect Your On-Premises Site to AWS Using Site-to-Site VPN.pdf
Tamanna
 
PPTX
apidays Munich 2025 - Building an AWS Serverless Application with Terraform, ...
apidays
 
PPT
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
PPTX
apidays Helsinki & North 2025 - Running a Successful API Program: Best Practi...
apidays
 
PPTX
apidays Munich 2025 - Building Telco-Aware Apps with Open Gateway APIs, Subhr...
apidays
 
PDF
Avatar for apidays apidays PRO June 07, 2025 0 5 apidays Helsinki & North 2...
apidays
 
PDF
Driving Employee Engagement in a Hybrid World.pdf
Mia scott
 
PDF
Data Chunking Strategies for RAG in 2025.pdf
Tamanna
 
PPTX
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
PDF
Choosing the Right Database for Indexing.pdf
Tamanna
 
PPTX
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
PDF
R Cookbook - Processing and Manipulating Geological spatial data with R.pdf
OtnielSimopiaref2
 
PDF
apidays Helsinki & North 2025 - API-Powered Journeys: Mobility in an API-Driv...
apidays
 
PDF
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
PDF
Copia de Strategic Roadmap Infographics by Slidesgo.pptx (1).pdf
ssuserd4c6911
 
PDF
Simplifying Document Processing with Docling for AI Applications.pdf
Tamanna
 
PPTX
Numbers of a nation: how we estimate population statistics | Accessible slides
Office for National Statistics
 
OPPOTUS - Malaysias on Malaysia 1Q2025.pdf
Oppotus
 
Web Scraping with Google Gemini 2.0 .pdf
Tamanna
 
Merits and Demerits of DBMS over File System & 3-Tier Architecture in DBMS
MD RIZWAN MOLLA
 
How to Connect Your On-Premises Site to AWS Using Site-to-Site VPN.pdf
Tamanna
 
apidays Munich 2025 - Building an AWS Serverless Application with Terraform, ...
apidays
 
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
apidays Helsinki & North 2025 - Running a Successful API Program: Best Practi...
apidays
 
apidays Munich 2025 - Building Telco-Aware Apps with Open Gateway APIs, Subhr...
apidays
 
Avatar for apidays apidays PRO June 07, 2025 0 5 apidays Helsinki & North 2...
apidays
 
Driving Employee Engagement in a Hybrid World.pdf
Mia scott
 
Data Chunking Strategies for RAG in 2025.pdf
Tamanna
 
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
Choosing the Right Database for Indexing.pdf
Tamanna
 
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
R Cookbook - Processing and Manipulating Geological spatial data with R.pdf
OtnielSimopiaref2
 
apidays Helsinki & North 2025 - API-Powered Journeys: Mobility in an API-Driv...
apidays
 
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
Copia de Strategic Roadmap Infographics by Slidesgo.pptx (1).pdf
ssuserd4c6911
 
Simplifying Document Processing with Docling for AI Applications.pdf
Tamanna
 
Numbers of a nation: how we estimate population statistics | Accessible slides
Office for National Statistics
 
Ad

LECT 29- EXCEPTION HANDLING.pptx b.

  • 2. Errors and Exceptions  Python Errors and Built-in Exceptions: Python (interpreter) raises exceptions when it encounters errors.  When writing a program, we, more often than not, will encounter errors.  Error caused by not following the proper structure (syntax) of the language is called syntax error or parsing error
  • 3.  An exception in Python is an incident that happens while executing a program that causes the regular course of the program's commands to be disrupted.  When a Python code comes across a condition it can't handle, it raises an exception.  An object in Python that describes an error is called an exception.
  • 6.  ZeroDivisionError: ZeroDivisionError in Python indicates that the second argument used in a division (or modulo) operation was zero.  OverflowError: OverflowError in Python indicates that an arithmetic operation has exceeded the limits of the current Python runtime. This is typically due to excessively large float values, as integer values that are too big will opt to raise memory errors instead.  ImportError: It is raised when you try to import a module which does not exist. This may happen if you made a typing mistake in the module name or the module doesn't exist in its standard path..
  • 7.  IndexError: An IndexError exception is raised when you refer a sequence which is out of range. In the example below, the list abc contains only 3 entries, but the 4th index is being accessed, which will result an IndexError exception.  TypeError: When two unrelated type of objects are combined, TypeErrorexception is raised.  IndentationError: Causes due to Unexpected indent.
  • 8.  Syntax errors: These are the most basic type of error. They arise when the Python parser is unable to understand a line of code. Syntax errors are almost always fatal, i.e. there is almost never a way to successfully execute a piece of code containing syntax errors.  Run-time error: A run-time error happens when Python understands what you are saying, but runs into trouble when following your instructions
  • 9.  Key Error : Python raises a KeyError whenever a dict() object is requested (using the format a = adict[key]) and the key is not in the dictionary.  Value Error: In Python, a value is the information that is stored within a certain object. To encounter a ValueError in Python means that is a problem with the content of the object you tried to assign the value to.
  • 10.  Python has many built-in exceptions:
  • 11.  Python uses try and except keywords to handle exceptions. Both keywords are followed by indented blocks
  • 12.  The things we need to observe are: 1. You should be able to understand the mistakes; the error might be done by user, DB connection or server. 2. Whenever there is an error execution should not stop. Ex: Banking Transaction 3. The aim is execution should not stop even though an error occurs
  • 20.  A try statement can have more than one except clause, to specify handlers for different exceptions.  Note that at most one handler will be executed.