Movatterモバイル変換


[0]ホーム

URL:


Uploaded byNagarathnaRajur2
PPTX, PDF31 views

EXCEPTIONS-PYTHON.pptx RUNTIME ERRORS HANDLING

The document explains the concept of exceptions in Python, detailing how they are runtime errors that can be handled by programmers. It outlines the steps for exception handling, including using 'try', 'except', and 'finally' blocks, and provides information on various built-in exception classes. Additionally, it introduces user-defined exceptions and provides guidelines for creating and handling them.

Embed presentation

Download to read offline
Exceptions
DefinitionAn exception is a runtime error which can be handled by theprogrammer. That means if the programmer can guess an error in theprogram and he can do something to eliminate the harm caused bythat error then it is called an exception. If error is not handled byprogrammer then it is called as error.All exceptions are represented as classes in python. The exceptionswhich are already available in python are called built-in exception.
Important exception classes in pythonBaseExceptionExceptionStandardError WarningDeprecationWarningRuntimeWarningImportWarningAssertionErrorSyntaxErrorTypeErrorEOFErrorRuntimeErrorImportErrorArthmeticErrorNameError
Exception HandlingPurpose of handling errors is to make program robust. It means strong.Robust program does not terminate in the middle. When there is a errordisplays appropriate message to the user and continue execution. Whenthe errors can be handled they are called exception.To handle the exception the programmer should perform the followingthree stepsStep1: The statement that may cause the exception must be written insidea ‘try’ blocktry:statementsIf statement raises an error then it enters into except block otherwisecontinues the execution
continuedStep2:Programmer should write except block where we should display the exception details to theuserexcept exception name:statements #these statements from handlerStep3:Lastly the programmer should perform clean up actions like closing the files and terminatingany other processes which are running.finally:statementsStatements inside the finally block are executed irrespective of whether there is an exception ornot. This ensures that all the opened files are properly closed and all the running processes areterminated properly.
Syntax for handling exceptiontry:statementsexcept Exception1:exception handler1except Exception2:exception handler2else:statementsfinally:statements
Types of ExceptionException Class Name DescriptionException Represents any type of exception. All exception are sub classes of this classArithmeticError Represents the base class for arithmetic errors like OverflowError,ZeroDivisionError, FloatingPointErrorAssertionError Raised when an assert statement gives errorAttributeError Raised when an attribute reference or assignment failsEOFError Raised when input() function reaches end of file condition without reading anydataFloatingPointError Raised when a floating operation failsGeneratorExit Raised when generators close() method is calledIOError Raised when an input or output operation failed. It raises when the file opened isnot found or when writing data disk is fullImportError Raised when an import statement fails to find the module being imported
continuedException Class Name DescriptionIndexError Raised when a sequence index or subscript is out of rangeKeyError Raised when a mapping (dictionary) key is not found in the set of existingkeysKeyboardInterrupt Raised when the user hits the interrupt key(Control-C, Delete)NameError Raised when an identifier is not found locally or globallyNotImplementedError Derived from runtimeError
Programs on exceptionPython program to handle ZeroDivisionError exceptionFilename:ep1.pyPython program to handle syntax error given by eval() functionFilename:ep2.pyPython program to handle multiple exceptionFilename:ep3.py
User Defined ExceptionLike the built in exceptions of python user can also create his ownexceptions which are called user defined exception or custom exception.EXAMPLE: Matainance of minimum balance in accountSteps to define user defined exception1.Create own exception class and is sub class of built in class Exceptionclass MyExecption(Exception):def __init__(self,arg):self.msg=argmsg is member of class MyException and is assigned with parameterreceived from outside
Continued2. When the programmer suspects the possibility of exception raise ownexception using raise statementRaise MyExecption(‘message’)3. Programmer must write the code inside a try block and catch theexception using except block astry:codeexcept MyException as meprint(me)Python program to illustrate user defined exceptionFilename:ep4.py
THANK YOU

Recommended

PPTX
Exception Handling in Python programming.pptx
PPTX
Exception Handling in Python Programming.pptx
PPTX
Exception handling with python class 12.pptx
PDF
EXCEPTION HANDLING - PYTHON COMPUTER SCIENCE
PPTX
Exception Handling in python programming.pptx
PPT
33aa27cae9c84fd12762a4ecdc288df822623524-1705207147822.ppt
PDF
Unit 4-Exception Handling in Python.pdf
DOCX
Exception handlingpdf
PDF
Python programming : Exceptions
PDF
lecs101.pdfgggggggggggggggggggddddddddddddb
PPTX
Errorhandlingbyvipulkendroyavidyalayacrpfmudkhed.pptx
PPTX
EXCEPTION HANDLING class 12th computer science.pptx
PPTX
Python Unit II.pptx
PPTX
Python Exception Handling
PPT
Exception Handling on 22nd March 2022.ppt
PPTX
Python Lecture 7
PPTX
Python_Exception_Handling_Presentation.pptx
PPTX
Exception Handling.pptx
PPT
Exception
PPTX
Exception handling.pptxnn h
PPTX
Chapter-12 Error and exception handling.pptx
PDF
Python Programming - X. Exception Handling and Assertions
PPTX
Python Exceptions Powerpoint Presentation
PPTX
Exception handling.pptx
PDF
Exception handling in python
PPTX
Error and exception in python
PPTX
Chapter 13 exceptional handling
PPT
Basics of C (2).ppt bbbbbbbbbbbbbbbbbbbbb
PPT
C-Programming Chapter 1 Fundamentals of C.ppt

More Related Content

PPTX
Exception Handling in Python programming.pptx
PPTX
Exception Handling in Python Programming.pptx
PPTX
Exception handling with python class 12.pptx
PDF
EXCEPTION HANDLING - PYTHON COMPUTER SCIENCE
PPTX
Exception Handling in python programming.pptx
PPT
33aa27cae9c84fd12762a4ecdc288df822623524-1705207147822.ppt
PDF
Unit 4-Exception Handling in Python.pdf
DOCX
Exception handlingpdf
Exception Handling in Python programming.pptx
Exception Handling in Python Programming.pptx
Exception handling with python class 12.pptx
EXCEPTION HANDLING - PYTHON COMPUTER SCIENCE
Exception Handling in python programming.pptx
33aa27cae9c84fd12762a4ecdc288df822623524-1705207147822.ppt
Unit 4-Exception Handling in Python.pdf
Exception handlingpdf

Similar to EXCEPTIONS-PYTHON.pptx RUNTIME ERRORS HANDLING

PDF
Python programming : Exceptions
PDF
lecs101.pdfgggggggggggggggggggddddddddddddb
PPTX
Errorhandlingbyvipulkendroyavidyalayacrpfmudkhed.pptx
PPTX
EXCEPTION HANDLING class 12th computer science.pptx
PPTX
Python Unit II.pptx
PPTX
Python Exception Handling
PPT
Exception Handling on 22nd March 2022.ppt
PPTX
Python Lecture 7
PPTX
Python_Exception_Handling_Presentation.pptx
PPTX
Exception Handling.pptx
PPT
Exception
PPTX
Exception handling.pptxnn h
PPTX
Chapter-12 Error and exception handling.pptx
PDF
Python Programming - X. Exception Handling and Assertions
PPTX
Python Exceptions Powerpoint Presentation
PPTX
Exception handling.pptx
PDF
Exception handling in python
PPTX
Error and exception in python
PPTX
Chapter 13 exceptional handling
Python programming : Exceptions
lecs101.pdfgggggggggggggggggggddddddddddddb
Errorhandlingbyvipulkendroyavidyalayacrpfmudkhed.pptx
EXCEPTION HANDLING class 12th computer science.pptx
Python Unit II.pptx
Python Exception Handling
Exception Handling on 22nd March 2022.ppt
Python Lecture 7
Python_Exception_Handling_Presentation.pptx
Exception Handling.pptx
Exception
Exception handling.pptxnn h
Chapter-12 Error and exception handling.pptx
Python Programming - X. Exception Handling and Assertions
Python Exceptions Powerpoint Presentation
Exception handling.pptx
Exception handling in python
Error and exception in python
Chapter 13 exceptional handling

More from NagarathnaRajur2

PPT
Basics of C (2).ppt bbbbbbbbbbbbbbbbbbbbb
PPT
C-Programming Chapter 1 Fundamentals of C.ppt
PPT
Basics of C.ppt VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
PPT
C-Programming Chapter 1 Fundamentals of C.ppt
PPT
lecture-ON-C.ppt BASIC WITH DEPTH CONTENT
PPTX
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
PPTX
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
PPTX
ppt on arm memory.pptx yjjghjghjjjjjjjj
PPTX
05_Thumb (15).pptx ARM MICROCONTROLLERS THUMB INSTRUCTIONS WORKING PRINCIPLE
PPT
PM.ppt DATA STRUCTURE USING C WITH EXAMPLE PROGRAMES
PPTX
8051 programes -ppt.pptx bnvmmmmmmmmmmmmmmmmmmmmmmmmmmhn
PPTX
Chapter_04_ARM_Assembly.pptx ARM ASSEMBLY CODE
PPT
MEMORY.ppt 8051/8052 MEMORY MANEGEMENT MEMORY DESCRIPTION
PPTX
CHAPTER1.pptx ON 8051 MICROCONTROLLER INTRODUCTION CHAPTER
PPTX
Core-Java-by-Mahika-Tutor.9459891.powerpoint.pptx
PPTX
review.pptx mnbmnbm,nb,n,nm,mn,mn,n,nm,
PPTX
IOT introduction with applications ffffffffffffffffffffff
PPTX
CORE JAVA PPT FOR ENGINEERS BBBBBBBBBBBBBBBBBBB
PPTX
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
PPTX
JavaSteps. PPT NBNBVNBNVBNNNNNNNNNNNNNN
Basics of C (2).ppt bbbbbbbbbbbbbbbbbbbbb
C-Programming Chapter 1 Fundamentals of C.ppt
Basics of C.ppt VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
C-Programming Chapter 1 Fundamentals of C.ppt
lecture-ON-C.ppt BASIC WITH DEPTH CONTENT
OPERATORS-PYTHON.pptx ALL OPERATORS ARITHMATIC AND LOGICAL
OOPS-PYTHON.pptx OOPS IN PYTHON APPLIED PROGRAMMING
ppt on arm memory.pptx yjjghjghjjjjjjjj
05_Thumb (15).pptx ARM MICROCONTROLLERS THUMB INSTRUCTIONS WORKING PRINCIPLE
PM.ppt DATA STRUCTURE USING C WITH EXAMPLE PROGRAMES
8051 programes -ppt.pptx bnvmmmmmmmmmmmmmmmmmmmmmmmmmmhn
Chapter_04_ARM_Assembly.pptx ARM ASSEMBLY CODE
MEMORY.ppt 8051/8052 MEMORY MANEGEMENT MEMORY DESCRIPTION
CHAPTER1.pptx ON 8051 MICROCONTROLLER INTRODUCTION CHAPTER
Core-Java-by-Mahika-Tutor.9459891.powerpoint.pptx
review.pptx mnbmnbm,nb,n,nm,mn,mn,n,nm,
IOT introduction with applications ffffffffffffffffffffff
CORE JAVA PPT FOR ENGINEERS BBBBBBBBBBBBBBBBBBB
JAVA CLASS PPT FOR ENGINEERING STUDENTS BBBBBBBBBBBBBBBBBBB
JavaSteps. PPT NBNBVNBNVBNNNNNNNNNNNNNN

Recently uploaded

PDF
LH_Lecture Note on Spices , AI And Importance in Human Life.pdf
PDF
Risk Management and Regulatory Compliance - by Ms. Oceana Wong
PPTX
ATTENTION - PART 1.pptx cognitive processes -For B.Sc I Sem By Mrs.Shilpa Hot...
PDF
AI Workflows and Workflow Rhetoric - by Ms. Oceana Wong
PDF
DEFINITION OF COMMUNITY Sociology. .pdf
PPTX
The hidden treasures Grade 5 Story with Motive Questions.pptx
PDF
AI and ICT for Teaching and Learning, Induction-cum-Training Programme, 5th 8...
PPTX
Photography Pillar 1 The Subject PowerPoint
PDF
*Unit-II A (Elements of Communication & Communication Style Matrix)
PDF
Digital Electronics – Registers and Their Applications
PPTX
General Wellness & Restorative Tonic: Draksharishta
PPTX
Physical education notes class ncert 12th
PPTX
Time Series Analysis - Weighted (Unequal) Moving Average Method
PDF
Integrated Circuits: Lithography Techniques - Fundamentals and Advanced Metho...
PPTX
Quarter 3 lesson 2 of English Grade 8.pptx
PPTX
A Presentation of PMES 2025-2028 with Salient features.pptx
PPTX
Prelims - History and Geography Quiz - Around the World in 80 Questions - IITK
PPTX
Plant Breeding: Its History and Contribution
PDF
Past Memories and a New World: Photographs of Stoke Newington from the 70s, 8...
PPTX
Time Series Analysis - Least Square Method Fitting a Linear Trend Equation
LH_Lecture Note on Spices , AI And Importance in Human Life.pdf
Risk Management and Regulatory Compliance - by Ms. Oceana Wong
ATTENTION - PART 1.pptx cognitive processes -For B.Sc I Sem By Mrs.Shilpa Hot...
AI Workflows and Workflow Rhetoric - by Ms. Oceana Wong
DEFINITION OF COMMUNITY Sociology. .pdf
The hidden treasures Grade 5 Story with Motive Questions.pptx
AI and ICT for Teaching and Learning, Induction-cum-Training Programme, 5th 8...
Photography Pillar 1 The Subject PowerPoint
*Unit-II A (Elements of Communication & Communication Style Matrix)
Digital Electronics – Registers and Their Applications
General Wellness & Restorative Tonic: Draksharishta
Physical education notes class ncert 12th
Time Series Analysis - Weighted (Unequal) Moving Average Method
Integrated Circuits: Lithography Techniques - Fundamentals and Advanced Metho...
Quarter 3 lesson 2 of English Grade 8.pptx
A Presentation of PMES 2025-2028 with Salient features.pptx
Prelims - History and Geography Quiz - Around the World in 80 Questions - IITK
Plant Breeding: Its History and Contribution
Past Memories and a New World: Photographs of Stoke Newington from the 70s, 8...
Time Series Analysis - Least Square Method Fitting a Linear Trend Equation

EXCEPTIONS-PYTHON.pptx RUNTIME ERRORS HANDLING

  • 1.
  • 2.
    DefinitionAn exception isa runtime error which can be handled by theprogrammer. That means if the programmer can guess an error in theprogram and he can do something to eliminate the harm caused bythat error then it is called an exception. If error is not handled byprogrammer then it is called as error.All exceptions are represented as classes in python. The exceptionswhich are already available in python are called built-in exception.
  • 3.
    Important exception classesin pythonBaseExceptionExceptionStandardError WarningDeprecationWarningRuntimeWarningImportWarningAssertionErrorSyntaxErrorTypeErrorEOFErrorRuntimeErrorImportErrorArthmeticErrorNameError
  • 4.
    Exception HandlingPurpose ofhandling errors is to make program robust. It means strong.Robust program does not terminate in the middle. When there is a errordisplays appropriate message to the user and continue execution. Whenthe errors can be handled they are called exception.To handle the exception the programmer should perform the followingthree stepsStep1: The statement that may cause the exception must be written insidea ‘try’ blocktry:statementsIf statement raises an error then it enters into except block otherwisecontinues the execution
  • 5.
    continuedStep2:Programmer should writeexcept block where we should display the exception details to theuserexcept exception name:statements #these statements from handlerStep3:Lastly the programmer should perform clean up actions like closing the files and terminatingany other processes which are running.finally:statementsStatements inside the finally block are executed irrespective of whether there is an exception ornot. This ensures that all the opened files are properly closed and all the running processes areterminated properly.
  • 6.
    Syntax for handlingexceptiontry:statementsexcept Exception1:exception handler1except Exception2:exception handler2else:statementsfinally:statements
  • 7.
    Types of ExceptionExceptionClass Name DescriptionException Represents any type of exception. All exception are sub classes of this classArithmeticError Represents the base class for arithmetic errors like OverflowError,ZeroDivisionError, FloatingPointErrorAssertionError Raised when an assert statement gives errorAttributeError Raised when an attribute reference or assignment failsEOFError Raised when input() function reaches end of file condition without reading anydataFloatingPointError Raised when a floating operation failsGeneratorExit Raised when generators close() method is calledIOError Raised when an input or output operation failed. It raises when the file opened isnot found or when writing data disk is fullImportError Raised when an import statement fails to find the module being imported
  • 8.
    continuedException Class NameDescriptionIndexError Raised when a sequence index or subscript is out of rangeKeyError Raised when a mapping (dictionary) key is not found in the set of existingkeysKeyboardInterrupt Raised when the user hits the interrupt key(Control-C, Delete)NameError Raised when an identifier is not found locally or globallyNotImplementedError Derived from runtimeError
  • 9.
    Programs on exceptionPythonprogram to handle ZeroDivisionError exceptionFilename:ep1.pyPython program to handle syntax error given by eval() functionFilename:ep2.pyPython program to handle multiple exceptionFilename:ep3.py
  • 10.
    User Defined ExceptionLikethe built in exceptions of python user can also create his ownexceptions which are called user defined exception or custom exception.EXAMPLE: Matainance of minimum balance in accountSteps to define user defined exception1.Create own exception class and is sub class of built in class Exceptionclass MyExecption(Exception):def __init__(self,arg):self.msg=argmsg is member of class MyException and is assigned with parameterreceived from outside
  • 11.
    Continued2. When theprogrammer suspects the possibility of exception raise ownexception using raise statementRaise MyExecption(‘message’)3. Programmer must write the code inside a try block and catch theexception using except block astry:codeexcept MyException as meprint(me)Python program to illustrate user defined exceptionFilename:ep4.py
  • 12.

[8]ページ先頭

©2009-2025 Movatter.jp