SlideShare a Scribd company logo
Python-Exception Handling
Syntax error
Syntax Error: As the name suggests this error is caused by the wrong
syntax in the code. It leads to the termination of the program.
Exceptions Error
Exceptions: Exceptions are raised when the program is syntactically
correct, but the code resulted in an error. This error does not stop the
execution of the program, however, it changes the normal flow of the
program.
Try and Except Statement – Catching
Exceptions
Try and except statements are used to catch and handle exceptions in
Python. Statements that can raise exceptions are kept inside the try
clause and the statements that handle the exception are written inside
except clause.
Catching Specific Exception
A try statement can have more than one except clause, to specify
handlers for different exceptions. Please note that at most one handler
will be executed. For example, we can add IndexError in the above
code. The general syntax for adding specific exceptions are –
try:
# statement(s)
except IndexError:
# statement(s)
except ValueError:
# statement(s)
Example
Try with Else Clause
In python, you can also use the else clause on the try-except block
which must be present after all the except clauses. The code enters the
else block only if the try clause does not raise an exception.

More Related Content

PPTX
Exception handling.pptx
PPTX
Errorhandlingbyvipulkendroyavidyalayacrpfmudkhed.pptx
PPTX
Python for beginners textbook slides ppt
PDF
Python exception handling
PPT
Exceptions in Java
PDF
14 exception handling
PPTX
Java SE 11 Exception Handling
PPT
Introduction of exception in vb.net
Exception handling.pptx
Errorhandlingbyvipulkendroyavidyalayacrpfmudkhed.pptx
Python for beginners textbook slides ppt
Python exception handling
Exceptions in Java
14 exception handling
Java SE 11 Exception Handling
Introduction of exception in vb.net

Similar to Python-exceptionHandling.pptx (20)

PPTX
Module 4.pptxModule 4.pptxModuModule 4.pptxModule 4.pptxle 4.pptx
PPTX
exception handling.pptx
PPT
Unit 5 Java
PPSX
Java Exceptions
PPSX
Java Exceptions Handling
PPTX
Exceptions overview
PPTX
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
PPT
Excetion handling Software Engineering Units
PPT
Error Correction Techniques
PPTX
Chapter 13 exceptional handling
PPT
Exception Handling using Python Libraries
PPTX
Coding standards
PPT
Java exception
PPTX
Exception handling in Java
PDF
Bt0074 oops with java2
PPT
Exception handling in python and how to handle it
PPTX
Exception Handling,finally,catch,throw,throws,try.pptx
PPT
Firoze_Errors_Exceptions in python__.ppt
PPT
Firoze_Errors_Exceptions in python__.ppt
PDF
Python Programming - X. Exception Handling and Assertions
Module 4.pptxModule 4.pptxModuModule 4.pptxModule 4.pptxle 4.pptx
exception handling.pptx
Unit 5 Java
Java Exceptions
Java Exceptions Handling
Exceptions overview
Exception Handling Multithreading: Fundamental of Exception; Exception types;...
Excetion handling Software Engineering Units
Error Correction Techniques
Chapter 13 exceptional handling
Exception Handling using Python Libraries
Coding standards
Java exception
Exception handling in Java
Bt0074 oops with java2
Exception handling in python and how to handle it
Exception Handling,finally,catch,throw,throws,try.pptx
Firoze_Errors_Exceptions in python__.ppt
Firoze_Errors_Exceptions in python__.ppt
Python Programming - X. Exception Handling and Assertions
Ad

More from Karudaiyar Ganapathy (8)

PPTX
Python-FileHandling.pptx
PPTX
Python-Encapsulation.pptx
PPTX
Python-DataAbstarction.pptx
PPTX
Overloading vs Overriding.pptx
PPTX
Python-Polymorphism.pptx
PPTX
Python-Inheritance.pptx
PPTX
Python-Classes.pptx
PPTX
Python-Functions.pptx
Python-FileHandling.pptx
Python-Encapsulation.pptx
Python-DataAbstarction.pptx
Overloading vs Overriding.pptx
Python-Polymorphism.pptx
Python-Inheritance.pptx
Python-Classes.pptx
Python-Functions.pptx
Ad

Recently uploaded (20)

PPTX
Nature of X-rays, X- Ray Equipment, Fluoroscopy
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PPTX
Current and future trends in Computer Vision.pptx
PPTX
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
PPTX
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PDF
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
Soil Improvement Techniques Note - Rabbi
PDF
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PPTX
Fundamentals of safety and accident prevention -final (1).pptx
PPTX
Software Engineering and software moduleing
PDF
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
PDF
Categorization of Factors Affecting Classification Algorithms Selection
PDF
737-MAX_SRG.pdf student reference guides
PPT
Total quality management ppt for engineering students
Nature of X-rays, X- Ray Equipment, Fluoroscopy
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
Current and future trends in Computer Vision.pptx
CURRICULAM DESIGN engineering FOR CSE 2025.pptx
6ME3A-Unit-II-Sensors and Actuators_Handouts.pptx
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
Accra-Kumasi Expressway - Prefeasibility Report Volume 1 of 7.11.2018.pdf
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Soil Improvement Techniques Note - Rabbi
Artificial Superintelligence (ASI) Alliance Vision Paper.pdf
Exploratory_Data_Analysis_Fundamentals.pdf
Fundamentals of safety and accident prevention -final (1).pptx
Software Engineering and software moduleing
22EC502-MICROCONTROLLER AND INTERFACING-8051 MICROCONTROLLER.pdf
Categorization of Factors Affecting Classification Algorithms Selection
737-MAX_SRG.pdf student reference guides
Total quality management ppt for engineering students

Python-exceptionHandling.pptx

  • 2. Syntax error Syntax Error: As the name suggests this error is caused by the wrong syntax in the code. It leads to the termination of the program.
  • 3. Exceptions Error Exceptions: Exceptions are raised when the program is syntactically correct, but the code resulted in an error. This error does not stop the execution of the program, however, it changes the normal flow of the program.
  • 4. Try and Except Statement – Catching Exceptions Try and except statements are used to catch and handle exceptions in Python. Statements that can raise exceptions are kept inside the try clause and the statements that handle the exception are written inside except clause.
  • 5. Catching Specific Exception A try statement can have more than one except clause, to specify handlers for different exceptions. Please note that at most one handler will be executed. For example, we can add IndexError in the above code. The general syntax for adding specific exceptions are – try: # statement(s) except IndexError: # statement(s) except ValueError: # statement(s)
  • 7. Try with Else Clause In python, you can also use the else clause on the try-except block which must be present after all the except clauses. The code enters the else block only if the try clause does not raise an exception.