Movatterモバイル変換


[0]ホーム

URL:


Exception handling in python

This document provides information about a mentoring program run by Baabtra-Mentoring Partner. It includes a trainee's typing speed progress over 5 weeks, with targets and achievements. It also lists 3 job applications with company names, designations, and application dates. Finally, it discusses Python exceptions handling, including try/catch blocks, built-in exception classes, raising exceptions, and error types.

Embed presentation

Download as ODP, PPTX
Disclaimer: This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
Typing SpeedWeekTargetAchieved1252323026330284353254038
Jobs Applied#123CompanyDesignationApplied DateCurrentStatus
Python Exceptions Handlingshafeeque●shafeequemonp@gmail.com●www.facebook.com/shafeequemonppambodan●twitter.com/shafeequemonp●in.linkedin.com/in/shafeequemonp●9809611325
What is Exception?●●An exception is an event, which occurs during the execution of a program, thatdisrupts the normal flow of the program's instructionsWhen a method encounters an abnormal condition (an exception condition) that itcan't handle itself, it may throw an exception.Exception classesprocess●In Java, exceptions are objects●When you throw an exception, you throw an object●●Throwable serves as the base class for an entire family of classes, declaredin javaThrowable has two direct subclasses-Exception-Error
●●●●●Exceptions (members of the Exception family) are thrown to signalabnormal conditions that can often be handled by some catcherThough it's possible they may not be caught and therefore couldresult in a dead thread.Errors (members of the Error family) are usually thrown for moreserious problems, such as OutOfMemoryErrorIn general, code you write should throw only exceptions, not errors.Errors are usually thrown by the methods of the Java API, or by theJava virtual machine itself
Catching Exceptions:●A method catches an exception using a combination othe try and catch keywords●A try/catch block is placed around the code that might generate an exception.●Code within a try/catch block is referred to as protected code●Syntax:●try{//Protected code}catch(ExceptionName e1){//Catch block}
// File Name : ExcepTest.javaimport java.io.*;public class ExcepTest{public static void main(String args[]){try{int a[] = new int[2];System.out.println("Access element three :" + a[3]);}catch(ArrayIndexOutOfBoundsException e){System.out.println("Exception thrown :" + e);}System.out.println("Out of the block");}}Output:Exception thrownOut of the block:java.lang.ArrayIndexOutOfBoundsException: 3
Errors and Exceptions:Syntax Errors●●It is also known as parsing errors, are perhaps the most common kind ofcomplaint you get while you are still learning Python>>> while True print 'Hello world'File "<stdin>", line 1, in ?while True print 'Hello world'^SyntaxError: invalid syntax●●●The parser repeats the offending line and displays a little ‘arrow’ pointingat the earliest point in the line where the error was detectedThe error is caused by (or at least detected at) the token preceding thearrow: in the example, the error is detected at the keyword print, since acolon (':') is missing before itFile name and line number are printed so you know where to look incase the input came from a script.
Exceptions:●Exceptions should be class objects●The exceptions are defined in the module exceptions●●●For class exceptions, in a try statement with an except clause thatmentions a particular classEven if a statement or expression is syntactically correct, it may causean error when an attempt is made to execute itErrors detected during execution are called exceptions and are notunconditionally fatal
●>>> 10 * (1/0)Traceback (most recent call last):File "<stdin>", line 1, in ?ZeroDivisionError: integer division or modulo by zero>>> 4 + spam*3Traceback (most recent call last):File "<stdin>", line 1, in ?NameError: name 'spam' is not defined>>> '2' + 2Traceback (most recent call last):File "<stdin>", line 1, in ?TypeError: cannot concatenate 'str' and 'int' objects
Handling Exceptions:.>>> while True:...try:...x = int(raw_input("Please enter a number: "))...break......except ValueError:print "Oops! That was no valid number. Try again..."●The try statement works as follows:●First, the try clause (the statement(s) between the try and except keywords) is executed.●●●If no exception occurs, the except clause is skipped and execution of the try statement isfinished.If an exception occurs during execution of the try clause, the rest of the clause is skipped.Then if its type matches the exception named after the except keyword, the except clauseis executed, and then execution continues after the try statement.If an exception occurs which does not match the exception named in the except clause, itis passed on to outer try statements; if no handler is found, it is an unhandled exceptionand execution stops with a message as shown above.
Raising Exceptions:●●The raise statement allows the programmer to force a specified exceptionto occur>>> raise NameError('HiThere')Traceback (most recent call last):File "<stdin>", line 1, in ?NameError: HiThere●●If you need to determine whether an exception was raised but don’tintend to handle it, a simpler form of the raise statement allows you to reraise the exception:>>> try:...raise NameError('HiThere')... except NameError:...print 'An exception flew by!'...raise...An exception flew by!Traceback (most recent call last):File "<stdin>", line 2, in ?NameError: HiThere
If this presentation helped you, please visit our page facebook.com/baabtra andlike it.Thanks in advance.www.baabtra.com | www.massbaab.com |www.baabte.com
Contact UsEmarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550Start up VillageEranakulam,Kerala, India.Email: info@baabtra.comNC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

Recommended

PDF
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
PPTX
Python Exception Handling
PDF
Python programming : Files
PDF
Python exception handling
PPT
Exception handling in java
PDF
Python programming : Exceptions
PPTX
Chapter 07 inheritance
PDF
Strings in Python
PDF
PPTX
Python Libraries and Modules
PPTX
Python OOPs
PPSX
Modules and packages in python
PPTX
Python-Inheritance.pptx
PPTX
Exception Handling in Java
PPTX
Class, object and inheritance in python
PPTX
Operator Overloading In Python
PPTX
File handling in Python
PPTX
Chapter 05 classes and objects
PPT
Exception Handling in JAVA
PDF
Python file handling
PPTX
Object oriented programming in python
PPTX
Functions in python
PPTX
Python 3 Programming Language
PDF
Python decision making
PPTX
File Handling Python
PPTX
Python-FileHandling.pptx
PPS
Java Exception handling
PPTX
Python Programming Essentials - M21 - Exception Handling
PDF

More Related Content

PDF
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
PPTX
Python Exception Handling
PDF
Python programming : Files
PDF
Python exception handling
PPT
Exception handling in java
PDF
Python programming : Exceptions
PPTX
Chapter 07 inheritance
PDF
Strings in Python
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Python Exception Handling
Python programming : Files
Python exception handling
Exception handling in java
Python programming : Exceptions
Chapter 07 inheritance
Strings in Python

What's hot

PDF
PPTX
Python Libraries and Modules
PPTX
Python OOPs
PPSX
Modules and packages in python
PPTX
Python-Inheritance.pptx
PPTX
Exception Handling in Java
PPTX
Class, object and inheritance in python
PPTX
Operator Overloading In Python
PPTX
File handling in Python
PPTX
Chapter 05 classes and objects
PPT
Exception Handling in JAVA
PDF
Python file handling
PPTX
Object oriented programming in python
PPTX
Functions in python
PPTX
Python 3 Programming Language
PDF
Python decision making
PPTX
File Handling Python
PPTX
Python-FileHandling.pptx
PPS
Java Exception handling
Python Libraries and Modules
Python OOPs
Modules and packages in python
Python-Inheritance.pptx
Exception Handling in Java
Class, object and inheritance in python
Operator Overloading In Python
File handling in Python
Chapter 05 classes and objects
Exception Handling in JAVA
Python file handling
Object oriented programming in python
Functions in python
Python 3 Programming Language
Python decision making
File Handling Python
Python-FileHandling.pptx
Java Exception handling

Viewers also liked

PPTX
Python Programming Essentials - M21 - Exception Handling
PDF
PDF
Python import mechanism
PDF
Python Programming - X. Exception Handling and Assertions
PPTX
Python basics
PPTX
Basics of Object Oriented Programming in Python
PPT
Introduction to Python
Python Programming Essentials - M21 - Exception Handling
Python import mechanism
Python Programming - X. Exception Handling and Assertions
Python basics
Basics of Object Oriented Programming in Python
Introduction to Python

Similar to Exception handling in python

PDF
EXCEPTION HANDLING - PYTHON COMPUTER SCIENCE
PPTX
EXCEPTIONS-PYTHON.pptx RUNTIME ERRORS HANDLING
PPTX
Exception Handling in Python programming.pptx
PPTX
Exception Handling in Python Programming.pptx
PPTX
Exception handling.pptxnn h
PPTX
Python Exceptions Powerpoint Presentation
PDF
Unit 4-Exception Handling in Python.pdf
PPT
Exception Handling on 22nd March 2022.ppt
PPTX
Errorhandlingbyvipulkendroyavidyalayacrpfmudkhed.pptx
PPTX
Mastering Errors and Exceptions in Python: A Comprehensive Guide
PDF
Wondershare UniConverter Crack FREE Download 2025 version
PDF
lecs101.pdfgggggggggggggggggggddddddddddddb
PPT
33aa27cae9c84fd12762a4ecdc288df822623524-1705207147822.ppt
PPT
Firoze_Errors_Exceptions in python__.ppt
PPT
Exception
PPTX
Chapter-12 Error and exception handling.pptx
EXCEPTION HANDLING - PYTHON COMPUTER SCIENCE
EXCEPTIONS-PYTHON.pptx RUNTIME ERRORS HANDLING
Exception Handling in Python programming.pptx
Exception Handling in Python Programming.pptx
Exception handling.pptxnn h
Python Exceptions Powerpoint Presentation
Unit 4-Exception Handling in Python.pdf
Exception Handling on 22nd March 2022.ppt
Errorhandlingbyvipulkendroyavidyalayacrpfmudkhed.pptx
Mastering Errors and Exceptions in Python: A Comprehensive Guide
Wondershare UniConverter Crack FREE Download 2025 version
lecs101.pdfgggggggggggggggggggddddddddddddb
33aa27cae9c84fd12762a4ecdc288df822623524-1705207147822.ppt
Firoze_Errors_Exceptions in python__.ppt
Exception
Chapter-12 Error and exception handling.pptx

More from baabtra.com - No. 1 supplier of quality freshers

PPTX
Agile methodology and scrum development
PDF
Acquiring new skills what you should know
PDF
Baabtra.com programming at school
PDF
99LMS for Enterprises - LMS that you will love
PPTX
PPTX
Chapter 6 database normalisation
PPTX
Chapter 5 transactions and dcl statements
PPTX
Chapter 4 functions, views, indexing
PPTX
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
PPTX
Chapter 1 introduction to sql server
PPTX
Chapter 1 introduction to sql server
Agile methodology and scrum development
Acquiring new skills what you should know
Baabtra.com programming at school
99LMS for Enterprises - LMS that you will love
Chapter 6 database normalisation
Chapter 5 transactions and dcl statements
Chapter 4 functions, views, indexing
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 1 introduction to sql server
Chapter 1 introduction to sql server

Recently uploaded

PDF
The Evolving Role of the CEO in the Age of AI
PDF
[DevFest Strasbourg 2025] - NodeJs Can do that !!
PDF
DUBAI IT MODERNIZATION WITH AZURE MANAGED SERVICES.pdf
PPTX
Support, Monitoring, Continuous Improvement & Scaling Agentic Automation [3/3]
PDF
Mastering Agentic Orchestration with UiPath Maestro | Hands on Workshop
PPTX
kernel PPT (Explanation of Windows Kernal).pptx
PDF
[BDD 2025 - Full-Stack Development] The Modern Stack: Building Web & AI Appli...
PDF
Cybersecurity Prevention and Detection: Unit 2
PDF
Transforming Supply Chains with Amazon Bedrock AgentCore (AWS Swiss User Grou...
PDF
5 Common Supply Chain Attacks and How They Work | CyberPro Magazine
PDF
Top Crypto Supers 15th Report November 2025
PPTX
Guardrails in Action - Ensuring Safe AI with Azure AI Content Safety.pptx
PDF
Dev Dives: Build smarter agents with UiPath Agent Builder
PDF
Mulesoft Meetup Online Portuguese: MCP e IA
PDF
How Much Does It Cost To Build Software
PPTX
Connecting the unconnectable: Exploring LoRaWAN for IoT
PPTX
Leon Brands - Intro to GPU Occlusion (Graphics Programming Conference 2024)
PDF
Transforming Content Operations in the Age of AI
PDF
Agentic Intro and Hands-on: Build your first Coded Agent
PDF
The partnership effect: Libraries and publishers on collaborating and thrivin...
The Evolving Role of the CEO in the Age of AI
[DevFest Strasbourg 2025] - NodeJs Can do that !!
DUBAI IT MODERNIZATION WITH AZURE MANAGED SERVICES.pdf
Support, Monitoring, Continuous Improvement & Scaling Agentic Automation [3/3]
Mastering Agentic Orchestration with UiPath Maestro | Hands on Workshop
kernel PPT (Explanation of Windows Kernal).pptx
[BDD 2025 - Full-Stack Development] The Modern Stack: Building Web & AI Appli...
Cybersecurity Prevention and Detection: Unit 2
Transforming Supply Chains with Amazon Bedrock AgentCore (AWS Swiss User Grou...
5 Common Supply Chain Attacks and How They Work | CyberPro Magazine
Top Crypto Supers 15th Report November 2025
Guardrails in Action - Ensuring Safe AI with Azure AI Content Safety.pptx
Dev Dives: Build smarter agents with UiPath Agent Builder
Mulesoft Meetup Online Portuguese: MCP e IA
How Much Does It Cost To Build Software
Connecting the unconnectable: Exploring LoRaWAN for IoT
Leon Brands - Intro to GPU Occlusion (Graphics Programming Conference 2024)
Transforming Content Operations in the Age of AI
Agentic Intro and Hands-on: Build your first Coded Agent
The partnership effect: Libraries and publishers on collaborating and thrivin...

Exception handling in python

  • 2.
    Disclaimer: This presentationis prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
  • 3.
  • 4.
  • 5.
  • 6.
    What is Exception?●●Anexception is an event, which occurs during the execution of a program, thatdisrupts the normal flow of the program's instructionsWhen a method encounters an abnormal condition (an exception condition) that itcan't handle itself, it may throw an exception.Exception classesprocess●In Java, exceptions are objects●When you throw an exception, you throw an object●●Throwable serves as the base class for an entire family of classes, declaredin javaThrowable has two direct subclasses-Exception-Error
  • 7.
    ●●●●●Exceptions (members ofthe Exception family) are thrown to signalabnormal conditions that can often be handled by some catcherThough it's possible they may not be caught and therefore couldresult in a dead thread.Errors (members of the Error family) are usually thrown for moreserious problems, such as OutOfMemoryErrorIn general, code you write should throw only exceptions, not errors.Errors are usually thrown by the methods of the Java API, or by theJava virtual machine itself
  • 8.
    Catching Exceptions:●A methodcatches an exception using a combination othe try and catch keywords●A try/catch block is placed around the code that might generate an exception.●Code within a try/catch block is referred to as protected code●Syntax:●try{//Protected code}catch(ExceptionName e1){//Catch block}
  • 9.
    // File Name: ExcepTest.javaimport java.io.*;public class ExcepTest{public static void main(String args[]){try{int a[] = new int[2];System.out.println("Access element three :" + a[3]);}catch(ArrayIndexOutOfBoundsException e){System.out.println("Exception thrown :" + e);}System.out.println("Out of the block");}}Output:Exception thrownOut of the block:java.lang.ArrayIndexOutOfBoundsException: 3
  • 10.
    Errors and Exceptions:SyntaxErrors●●It is also known as parsing errors, are perhaps the most common kind ofcomplaint you get while you are still learning Python>>> while True print 'Hello world'File "<stdin>", line 1, in ?while True print 'Hello world'^SyntaxError: invalid syntax●●●The parser repeats the offending line and displays a little ‘arrow’ pointingat the earliest point in the line where the error was detectedThe error is caused by (or at least detected at) the token preceding thearrow: in the example, the error is detected at the keyword print, since acolon (':') is missing before itFile name and line number are printed so you know where to look incase the input came from a script.
  • 11.
    Exceptions:●Exceptions should beclass objects●The exceptions are defined in the module exceptions●●●For class exceptions, in a try statement with an except clause thatmentions a particular classEven if a statement or expression is syntactically correct, it may causean error when an attempt is made to execute itErrors detected during execution are called exceptions and are notunconditionally fatal
  • 12.
    ●>>> 10 *(1/0)Traceback (most recent call last):File "<stdin>", line 1, in ?ZeroDivisionError: integer division or modulo by zero>>> 4 + spam*3Traceback (most recent call last):File "<stdin>", line 1, in ?NameError: name 'spam' is not defined>>> '2' + 2Traceback (most recent call last):File "<stdin>", line 1, in ?TypeError: cannot concatenate 'str' and 'int' objects
  • 13.
    Handling Exceptions:.>>> whileTrue:...try:...x = int(raw_input("Please enter a number: "))...break......except ValueError:print "Oops! That was no valid number. Try again..."●The try statement works as follows:●First, the try clause (the statement(s) between the try and except keywords) is executed.●●●If no exception occurs, the except clause is skipped and execution of the try statement isfinished.If an exception occurs during execution of the try clause, the rest of the clause is skipped.Then if its type matches the exception named after the except keyword, the except clauseis executed, and then execution continues after the try statement.If an exception occurs which does not match the exception named in the except clause, itis passed on to outer try statements; if no handler is found, it is an unhandled exceptionand execution stops with a message as shown above.
  • 14.
    Raising Exceptions:●●The raisestatement allows the programmer to force a specified exceptionto occur>>> raise NameError('HiThere')Traceback (most recent call last):File "<stdin>", line 1, in ?NameError: HiThere●●If you need to determine whether an exception was raised but don’tintend to handle it, a simpler form of the raise statement allows you to reraise the exception:>>> try:...raise NameError('HiThere')... except NameError:...print 'An exception flew by!'...raise...An exception flew by!Traceback (most recent call last):File "<stdin>", line 2, in ?NameError: HiThere
  • 18.
    If this presentationhelped you, please visit our page facebook.com/baabtra andlike it.Thanks in advance.www.baabtra.com | www.massbaab.com |www.baabte.com
  • 19.
    Contact UsEmarald Mall(Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550Start up VillageEranakulam,Kerala, India.Email: info@baabtra.comNC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550

Editor's Notes


[8]ページ先頭

©2009-2025 Movatter.jp