Submit Search
Upload
Python Programming Essentials - M21 - Exception Handling
•
7 likes
•
2,120 views
P3 InfoTech Solutions Pvt. Ltd.
Follow
Slides from the training on the topic "Python Programming Essentials"
Read less
Read more
Report
Share
Report
Share
1 of 18
Recommended
Exception Handling in Python - Rik van Achterberg & Tim Muller
Exception Handling in Python - Rik van Achterberg & Tim Muller
Byte
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Edureka!
Python Programming Essentials - M39 - Unit Testing
Python Programming Essentials - M39 - Unit Testing
P3 InfoTech Solutions Pvt. Ltd.
Python exceptions
Python exceptions
rikbyte
Python exception handling
Python exception handling
Mohammed Sikander
Exceptions in python
Exceptions in python
baabtra.com - No. 1 supplier of quality freshers
Presentation1
Presentation1
Anul Chaudhary
Python programming : Exceptions
Python programming : Exceptions
Emertxe Information Technologies Pvt Ltd
Recommended
Exception Handling in Python - Rik van Achterberg & Tim Muller
Exception Handling in Python - Rik van Achterberg & Tim Muller
Byte
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Exception Handling In Python | Exceptions In Python | Python Programming Tuto...
Edureka!
Python Programming Essentials - M39 - Unit Testing
Python Programming Essentials - M39 - Unit Testing
P3 InfoTech Solutions Pvt. Ltd.
Python exceptions
Python exceptions
rikbyte
Python exception handling
Python exception handling
Mohammed Sikander
Exceptions in python
Exceptions in python
baabtra.com - No. 1 supplier of quality freshers
Presentation1
Presentation1
Anul Chaudhary
Python programming : Exceptions
Python programming : Exceptions
Emertxe Information Technologies Pvt Ltd
Exception handling in python
Exception handling in python
Lifna C.S
Exception handling in c
Exception handling in c
Memo Yekem
Python Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and Assertions
Ranel Padon
Python Programming Essentials - M35 - Iterators & Generators
Python Programming Essentials - M35 - Iterators & Generators
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
P3 InfoTech Solutions Pvt. Ltd.
Exception handling
Exception handling
Pranali Chaudhari
C# Exceptions Handling
C# Exceptions Handling
sharqiyem
Exception Handling in the C++ Constructor
Exception Handling in the C++ Constructor
Somenath Mukhopadhyay
Exception handling
Exception handling
Iblesoft
exception handling in cpp
exception handling in cpp
gourav kottawar
Rc2010 tdd
Rc2010 tdd
JasonOffutt
Exception handling
Exception handling
pooja kumari
Exception handling c++
Exception handling c++
Jayant Dalvi
Exception handling and templates
Exception handling and templates
farhan amjad
What is Exception Handling?
What is Exception Handling?
Syed Bahadur Shah
Exception handling
Exception handling
Prafull Johri
C++ ala
C++ ala
Megha Patel
Exception handling in ASP .NET
Exception handling in ASP .NET
baabtra.com - No. 1 supplier of quality freshers
Understanding Exception Handling in .Net
Understanding Exception Handling in .Net
Mindfire Solutions
Exception handler
Exception handler
dishni
Exception handling in python
Exception handling in python
baabtra.com - No. 1 supplier of quality freshers
Libraries
Libraries
Marieswaran Ramasamy
More Related Content
What's hot
Exception handling in python
Exception handling in python
Lifna C.S
Exception handling in c
Exception handling in c
Memo Yekem
Python Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and Assertions
Ranel Padon
Python Programming Essentials - M35 - Iterators & Generators
Python Programming Essentials - M35 - Iterators & Generators
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
P3 InfoTech Solutions Pvt. Ltd.
Exception handling
Exception handling
Pranali Chaudhari
C# Exceptions Handling
C# Exceptions Handling
sharqiyem
Exception Handling in the C++ Constructor
Exception Handling in the C++ Constructor
Somenath Mukhopadhyay
Exception handling
Exception handling
Iblesoft
exception handling in cpp
exception handling in cpp
gourav kottawar
Rc2010 tdd
Rc2010 tdd
JasonOffutt
Exception handling
Exception handling
pooja kumari
Exception handling c++
Exception handling c++
Jayant Dalvi
Exception handling and templates
Exception handling and templates
farhan amjad
What is Exception Handling?
What is Exception Handling?
Syed Bahadur Shah
Exception handling
Exception handling
Prafull Johri
C++ ala
C++ ala
Megha Patel
Exception handling in ASP .NET
Exception handling in ASP .NET
baabtra.com - No. 1 supplier of quality freshers
Understanding Exception Handling in .Net
Understanding Exception Handling in .Net
Mindfire Solutions
Exception handler
Exception handler
dishni
What's hot
(20)
Exception handling in python
Exception handling in python
Exception handling in c
Exception handling in c
Python Programming - X. Exception Handling and Assertions
Python Programming - X. Exception Handling and Assertions
Python Programming Essentials - M35 - Iterators & Generators
Python Programming Essentials - M35 - Iterators & Generators
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
Python Programming Essentials - M37 - Brief Overview of Misc Concepts
Exception handling
Exception handling
C# Exceptions Handling
C# Exceptions Handling
Exception Handling in the C++ Constructor
Exception Handling in the C++ Constructor
Exception handling
Exception handling
exception handling in cpp
exception handling in cpp
Rc2010 tdd
Rc2010 tdd
Exception handling
Exception handling
Exception handling c++
Exception handling c++
Exception handling and templates
Exception handling and templates
What is Exception Handling?
What is Exception Handling?
Exception handling
Exception handling
C++ ala
C++ ala
Exception handling in ASP .NET
Exception handling in ASP .NET
Understanding Exception Handling in .Net
Understanding Exception Handling in .Net
Exception handler
Exception handler
Viewers also liked
Exception handling in python
Exception handling in python
baabtra.com - No. 1 supplier of quality freshers
Libraries
Libraries
Marieswaran Ramasamy
Python Programming Essentials - M4 - Editors and IDEs
Python Programming Essentials - M4 - Editors and IDEs
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String Formatting
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M8 - String Methods
Python Programming Essentials - M8 - String Methods
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M23 - datetime module
Python Programming Essentials - M23 - datetime module
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M1 - Course Introduction
Python Programming Essentials - M1 - Course Introduction
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M7 - Strings
Python Programming Essentials - M7 - Strings
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M40 - Invoking External Programs
Python Programming Essentials - M40 - Invoking External Programs
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M28 - Debugging with pdb
Python Programming Essentials - M28 - Debugging with pdb
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M31 - PEP 8
Python Programming Essentials - M31 - PEP 8
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M44 - Overview of Web Development
P3 InfoTech Solutions Pvt. Ltd.
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
Viewers also liked
(14)
Exception handling in python
Exception handling in python
Libraries
Libraries
Python Programming Essentials - M4 - Editors and IDEs
Python Programming Essentials - M4 - Editors and IDEs
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
Python Programming Essentials - M10 - Numbers and Artihmetic Operators
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M9 - String Formatting
Python Programming Essentials - M8 - String Methods
Python Programming Essentials - M8 - String Methods
Python Programming Essentials - M23 - datetime module
Python Programming Essentials - M23 - datetime module
Python Programming Essentials - M1 - Course Introduction
Python Programming Essentials - M1 - Course Introduction
Python Programming Essentials - M7 - Strings
Python Programming Essentials - M7 - Strings
Python Programming Essentials - M40 - Invoking External Programs
Python Programming Essentials - M40 - Invoking External Programs
Python Programming Essentials - M28 - Debugging with pdb
Python Programming Essentials - M28 - Debugging with pdb
Python Programming Essentials - M31 - PEP 8
Python Programming Essentials - M31 - PEP 8
Python Programming Essentials - M44 - Overview of Web Development
Python Programming Essentials - M44 - Overview of Web Development
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Similar to Python Programming Essentials - M21 - Exception Handling
Python Unit II.pptx
Python Unit II.pptx
sarthakgithub
Error and exception in python
Error and exception in python
junnubabu
Python Exception Handling
Python Exception Handling
Megha V
exception-handling-in-java.ppt
exception-handling-in-java.ppt
SanthiNivas
A exception ekon16
A exception ekon16
Max Kleiner
Handling Exceptions In C & C++[Part A]
Handling Exceptions In C & C++[Part A]
ppd1961
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
Mohammad Reza Kamalifard
Exception handling
Exception handling
Waqas Abbasi
Exception handling
Exception handling
Karthik Sekar
Exceptions in java
Exceptions in java
JasmeetSingh326
JAVA PROGRAMMING- Exception handling - Multithreading
JAVA PROGRAMMING- Exception handling - Multithreading
Jyothishmathi Institute of Technology and Science Karimnagar
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
AboMohammad10
Exception Handling
Exception Handling
Reddhi Basu
Exception handling
Exception handling
zindadili
43c
43c
Sireesh K
L14 exception handling
L14 exception handling
teach4uin
Unit iii pds
Unit iii pds
Kongunadu College of Engineering and Technology
Exception Handling
Exception Handling
Alpesh Oza
JP ASSIGNMENT SERIES PPT.ppt
JP ASSIGNMENT SERIES PPT.ppt
JAYAPRIYAR7
Python Lecture 7
Python Lecture 7
Inzamam Baig
Similar to Python Programming Essentials - M21 - Exception Handling
(20)
Python Unit II.pptx
Python Unit II.pptx
Error and exception in python
Error and exception in python
Python Exception Handling
Python Exception Handling
exception-handling-in-java.ppt
exception-handling-in-java.ppt
A exception ekon16
A exception ekon16
Handling Exceptions In C & C++[Part A]
Handling Exceptions In C & C++[Part A]
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱
Exception handling
Exception handling
Exception handling
Exception handling
Exceptions in java
Exceptions in java
JAVA PROGRAMMING- Exception handling - Multithreading
JAVA PROGRAMMING- Exception handling - Multithreading
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
Exception Handling
Exception Handling
Exception handling
Exception handling
43c
43c
L14 exception handling
L14 exception handling
Unit iii pds
Unit iii pds
Exception Handling
Exception Handling
JP ASSIGNMENT SERIES PPT.ppt
JP ASSIGNMENT SERIES PPT.ppt
Python Lecture 7
Python Lecture 7
More from P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M34 - List Comprehensions
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M29 - Python Interpreter and Files
Python Programming Essentials - M29 - Python Interpreter and Files
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging module
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modules
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M24 - math module
Python Programming Essentials - M24 - math module
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M22 - File Operations
Python Programming Essentials - M22 - File Operations
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M20 - Classes and Objects
Python Programming Essentials - M20 - Classes and Objects
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M18 - Modules and Packages
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M17 - Functions
Python Programming Essentials - M17 - Functions
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and Loops
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M15 - References
Python Programming Essentials - M15 - References
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M14 - Dictionaries
Python Programming Essentials - M14 - Dictionaries
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M13 - Tuples
Python Programming Essentials - M13 - Tuples
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M12 - Lists
Python Programming Essentials - M12 - Lists
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M11 - Comparison and Logical Operators
Python Programming Essentials - M11 - Comparison and Logical Operators
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M6 - Code Blocks and Indentation
Python Programming Essentials - M6 - Code Blocks and Indentation
P3 InfoTech Solutions Pvt. Ltd.
Python Programming Essentials - M5 - Variables
Python Programming Essentials - M5 - Variables
P3 InfoTech Solutions Pvt. Ltd.
More from P3 InfoTech Solutions Pvt. Ltd.
(18)
Python Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M34 - List Comprehensions
Python Programming Essentials - M29 - Python Interpreter and Files
Python Programming Essentials - M29 - Python Interpreter and Files
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M27 - Logging module
Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M25 - os and sys modules
Python Programming Essentials - M24 - math module
Python Programming Essentials - M24 - math module
Python Programming Essentials - M22 - File Operations
Python Programming Essentials - M22 - File Operations
Python Programming Essentials - M20 - Classes and Objects
Python Programming Essentials - M20 - Classes and Objects
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
Python Programming Essentials - M19 - Namespaces, Global Variables and Docstr...
Python Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M18 - Modules and Packages
Python Programming Essentials - M17 - Functions
Python Programming Essentials - M17 - Functions
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M15 - References
Python Programming Essentials - M15 - References
Python Programming Essentials - M14 - Dictionaries
Python Programming Essentials - M14 - Dictionaries
Python Programming Essentials - M13 - Tuples
Python Programming Essentials - M13 - Tuples
Python Programming Essentials - M12 - Lists
Python Programming Essentials - M12 - Lists
Python Programming Essentials - M11 - Comparison and Logical Operators
Python Programming Essentials - M11 - Comparison and Logical Operators
Python Programming Essentials - M6 - Code Blocks and Indentation
Python Programming Essentials - M6 - Code Blocks and Indentation
Python Programming Essentials - M5 - Variables
Python Programming Essentials - M5 - Variables
Python Programming Essentials - M21 - Exception Handling
1.
http://www.skillbrew.com /Skillbrew Talent brewed by
the industry itself Exception Handling in python Pavan Verma @YinYangPavan Founder, P3 InfoTech Solutions Pvt. Ltd. 1 Python Programming Essentials
2.
© SkillBrew http://skillbrew.com Contents
Exceptions Throwing and catching exceptions try except try except else try except finally Common python exceptions 2
3.
© SkillBrew http://skillbrew.com What
is an Exception? An exception is an error that happens during execution of a program If an exception is not caught the program is terminated In Python, exceptions are triggered automatically on errors, and they can be triggered and intercepted by your code 3
4.
© SkillBrew http://skillbrew.com Exceptions
Exception handling has two steps: • Raising or Throwing • Catching Python provides 3 keywords to deal with exceptions : • raise • try • except 4
5.
© SkillBrew http://skillbrew.com Exceptions
(2) Program to divide a constant by a number def divide(num): print 100/num if __name__ == '__main__': divide(0) OUPUT: ZeroDivisionError: integer division or modulo by zero 5
6.
© SkillBrew http://skillbrew.com Exception
propagation 6 >>> f1(0) Traceback (most recent call last): File "<pyshell#10>", line 1, in <module> f1(0) File "<pyshell#8>", line 2, in f1 return f2(num) File "<pyshell#5>", line 2, in f2 return f3(num) File "<pyshell#2>", line 3, in f3 return constant/num ZeroDivisionError: integer division or modulo by zero >>> def f3(num): constant = 100 return constant/num >>> def f2(num): return f3(num) >>> def f1(num): return f2(num) >>> f1(10) 10 >>> f1(0)
7.
© SkillBrew http://skillbrew.com Why
use exceptions Error handling: Python raises an exception whenever it detects errors in program at runtime. You can catch and respond to errors in the code or Python’s default behavior kicks in, stops the program and prints the error message. Event notification: exceptions can also be used to signal valid conditions without you having to pass result flags around a program 7
8.
© SkillBrew http://skillbrew.com Throwing
and Catching Exceptions 8
9.
© SkillBrew http://skillbrew.com Throwing
an exception 9 def avg(seq): result = 0 for val in seq: result += convert(val) return result/len(seq) def convert(val): try: val = int(val) except ValueError: raise ValueError('val type is not int') return val print avg([1, 2, 4, 5]) Output: 3
10.
© SkillBrew http://skillbrew.com Throwing
an exception 10 print avg([1, 'two', 4, 5]) Output: Traceback (most recent call last): File "exceptions1.py", line 15, in <module> print avg([1, 'two', 4, 5]) File "exceptions1.py", line 4, in avg result += convert(val) File "exceptions1.py", line 11, in convert raise ValueError('val type is not int') ValueError: val type is not int
11.
© SkillBrew http://skillbrew.com Handling
Exceptions (try except block) In order to handle exceptions wrap the code in try except def divide(num): try: print 100/num except ZeroDivisionError: print("division by Zero not allowed") if __name__=='__main__': divide(0) Output: division by Zero not allowed 11
12.
© SkillBrew http://skillbrew.com try
except else 12 try: # do something except: # handle exception else: # executed only when there is no exception The code in else block is only executed if there is no exception
13.
© SkillBrew http://skillbrew.com try
except else (2) def divide(num): try: result = 100/num except ZeroDivisionError: print('division by Zero not allowed') else: print “Result is %d" % (result) if __name__ == '__main__': divide(10) Output: Result is 10 13
14.
© SkillBrew http://skillbrew.com try
except finally 14 try: # do something except: # handle exception finally: # always executed The code in finally block is always executed, no matter what
15.
© SkillBrew http://skillbrew.com try
except finally (2) 15 def divide(num): try: result = 100/num except ZeroDivisionError: print('division by Zero not allowed') finally: print “Input was %d" % (num) if __name__ == '__main__': divide(0) Output: Division by Zero not allowed Your input was 0
16.
© SkillBrew http://skillbrew.com Common
Python Exceptions Exception Description IOError If the file cannot be opened ImportError If python cannot find the module ValueError Raised when a built-in operation or function receives an argument that has the right type but an inappropriate value KeyError Raised when a mapping (dictionary) key is not found in the set of existing keys IndentationError raised due to incorrect indentation SyntaxError Raised when the parser encounters a syntax error 16
17.
© SkillBrew http://skillbrew.com Custom
exceptions class MyException(Exception): pass def divide(num): try: return 100/num except ZeroDivisionError: raise MyException('Cannot divide by 0') 17
18.
© SkillBrew http://skillbrew.com Resources
http://doughellmann.com/2009/06/pyth on-exception-handling-techniques.html 18