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 with python class 12.pptx
PPTX
Exception Handling in Python programming.pptx
PPTX
Exception Handling in Python Programming.pptx
PDF
Unit 4-Exception Handling in Python.pdf
PDF
EXCEPTION HANDLING - PYTHON COMPUTER SCIENCE
PPTX
Exception Handling in python programming.pptx
DOCX
Exception handlingpdf
PPT
33aa27cae9c84fd12762a4ecdc288df822623524-1705207147822.ppt
PPTX
Python Unit II.pptx
PPTX
EXCEPTION HANDLING class 12th computer science.pptx
PDF
lecs101.pdfgggggggggggggggggggddddddddddddb
PPTX
Chapter 13 exceptional handling
PPTX
Python Exception Handling
PDF
Python programming : Exceptions
PPTX
Exception Handling.pptx
PPTX
Exception handling.pptxnn h
PPTX
Error and exception in python
PPTX
Chapter-12 Error and exception handling.pptx
PDF
Python Programming - X. Exception Handling and Assertions
PPTX
Python Exceptions Powerpoint Presentation
PDF
Exception handling in python
PPT
Exception Handling on 22nd March 2022.ppt
PPTX
Python_Exception_Handling_Presentation.pptx
PPTX
Errorhandlingbyvipulkendroyavidyalayacrpfmudkhed.pptx
PPTX
Python Lecture 7
PPT
Exception
PPTX
Exception handling.pptx
PPT
C-Programming Chapter 1 Fundamentals of C.ppt
PPTX
review.pptx mnbmnbm,nb,n,nm,mn,mn,n,nm,

More Related Content

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

Similar to EXCEPTIONS-PYTHON.pptx RUNTIME ERRORS HANDLING

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

More from NagarathnaRajur2

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

Recently uploaded

PDF
Past Memories and a New World: Photographs of Stoke Newington from the 70s, 8...
PDF
The invasion of Alexander of Macedonia in India
PPTX
The hidden treasures Grade 5 Story with Motive Questions.pptx
PDF
বাংলাদেশ অর্থনৈতিক সমীক্ষা - ২০২৫ with Bookmark.pdf
PDF
DEFINITION OF COMMUNITY Sociology. .pdf
PDF
Deep Research and Analysis - by Ms. Oceana Wong
PPTX
Plant Breeding: Its History and Contribution
PDF
CXC-AD Associate Degree Handbook (Revised)
PPTX
kklklklklklklklk;lkpoipor[3rjdkjoe99759893058085
PPTX
Screening and Selecting Studies for Systematic Review Dr Reginald Quansah
PDF
1. Doing Academic Research: Problems and Issues, 2. Academic Research Writing...
PDF
Integrated Circuits: Lithography Techniques - Fundamentals and Advanced Metho...
PPTX
Time Series Analysis - Meaning, Definition, Components and Application
PDF
LH_Lecture Note on Spices , AI And Importance in Human Life.pdf
PPTX
LYMPHATIC SYSTEM.pptx it includes lymph, lymph nodes, bone marrow, spleen
PPTX
Physical education notes class ncert 12th
PDF
*Unit-II A (Elements of Communication & Communication Style Matrix)
PPTX
Time Series Analysis - Least Square Method Fitting a Linear Trend Equation
PPTX
A Presentation of PMES 2025-2028 with Salient features.pptx
PPTX
ATTENTION - PART 1.pptx cognitive processes -For B.Sc I Sem By Mrs.Shilpa Hot...
Past Memories and a New World: Photographs of Stoke Newington from the 70s, 8...
The invasion of Alexander of Macedonia in India
The hidden treasures Grade 5 Story with Motive Questions.pptx
বাংলাদেশ অর্থনৈতিক সমীক্ষা - ২০২৫ with Bookmark.pdf
DEFINITION OF COMMUNITY Sociology. .pdf
Deep Research and Analysis - by Ms. Oceana Wong
Plant Breeding: Its History and Contribution
CXC-AD Associate Degree Handbook (Revised)
kklklklklklklklk;lkpoipor[3rjdkjoe99759893058085
Screening and Selecting Studies for Systematic Review Dr Reginald Quansah
1. Doing Academic Research: Problems and Issues, 2. Academic Research Writing...
Integrated Circuits: Lithography Techniques - Fundamentals and Advanced Metho...
Time Series Analysis - Meaning, Definition, Components and Application
LH_Lecture Note on Spices , AI And Importance in Human Life.pdf
LYMPHATIC SYSTEM.pptx it includes lymph, lymph nodes, bone marrow, spleen
Physical education notes class ncert 12th
*Unit-II A (Elements of Communication & Communication Style Matrix)
Time Series Analysis - Least Square Method Fitting a Linear Trend Equation
A Presentation of PMES 2025-2028 with Salient features.pptx
ATTENTION - PART 1.pptx cognitive processes -For B.Sc I Sem By Mrs.Shilpa Hot...

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