SlideShare a Scribd company logo
1 of 16
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
EXCEPTIONS IN PYTHON

SHAMEENA.V
shameenavayoli@gmail.com
www.facebook.com/shamee
na latheef
twitter.com/shameena
in.linkedin.com/in/shamean
9567135569
Introduction :
Python uses exceptions to communicate
errors and anomalies
 exception is an object that indicates an error
or anomalous condition
code explicitly raise an exception by executing
a raise statement.
 If a program does not handle an exception, it
terminates with an error traceback message
The try Statement
• The try statement provides Python's
exception-handling mechanism
• It is a compound statement
• It can take one of two different forms:
1) try clause followed by one or more except
clauses
2) A try clause followed by exactly one finally
clause
1)try/except
Syntax:
try:
statement(s)
except [expression [, target]]:
statement(s)
[else:
statement(s)]
Contd….
• The body of each except clause is known as an
exception handler
2) try/finally
Syntax:
try:
statement(s)
finally:
statement(s)
The finally clause establishes what is known
as a clean-up handler
Example :
f = open(someFile, "w")
try:
do_something_with_file(f)
finally:
f.close( )
Built-In Exception classes
• BaseException
mother of all exceptions
• Exception :
StandardError(base class for all built in
exception)
ArithmeticError
FloatingPointError
OverflowError
ZeroDivisionError
AttributeError (On attribute reference or assignment failure )
EnvironmentError (On error outside Python)
IOError
OSError
WindowsError

ImportError (On failure of import to find module or name.)
LookupError
base class for IndexError, KeyError
– IndexError
On out-of-range sequence subscript

- KeyError
On reference to a non-existent mapping (dict) key
NameError
UnBoundLocalError
On reference to an unassigned local variable

SyntaxError
On parser encountering a syntax error
– IndentationError
On parser encountering an indentation syntax error
--TabError
On improper mixture of spaces and tabs
Example:
try:
con = psycopg2.connect(database='testdb', user='shafeequemonp' )
cur = con.cursor()
print "Connecting to databasen
->%s" % (con)
cur.execute("""INSERT INTO tbl_user(vchr_username)
VALUES(%s)""",(ins_login_base.str_name))
con.commit()
except psycopg2.DatabaseError, e:
if con:
con.rollback()
print 'Error %s' % e
sys.exit(1)
finally:
if con:
con.close()
return
THANKS
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.

Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550

Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550

More Related Content

What's hot

Generators In Python
Generators In PythonGenerators In Python
Generators In PythonSimplilearn
 
Iterarators and generators in python
Iterarators and generators in pythonIterarators and generators in python
Iterarators and generators in pythonSarfaraz Ghanta
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception HandlingRTS Tech
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception HandlingMegha V
 
Python GUI Programming
Python GUI ProgrammingPython GUI Programming
Python GUI ProgrammingRTS Tech
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc csKALAISELVI P
 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Edureka!
 
Exception handling and function in python
Exception handling and function in pythonException handling and function in python
Exception handling and function in pythonTMARAGATHAM
 
Function arguments In Python
Function arguments In PythonFunction arguments In Python
Function arguments In PythonAmit Upadhyay
 
Advance OOP concepts in Python
Advance OOP concepts in PythonAdvance OOP concepts in Python
Advance OOP concepts in PythonSujith Kumar
 

What's hot (20)

Generators In Python
Generators In PythonGenerators In Python
Generators In Python
 
Namespaces
NamespacesNamespaces
Namespaces
 
Iterarators and generators in python
Iterarators and generators in pythonIterarators and generators in python
Iterarators and generators in python
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
 
Python GUI Programming
Python GUI ProgrammingPython GUI Programming
Python GUI Programming
 
Sets in python
Sets in pythonSets in python
Sets in python
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
Python modules
Python modulesPython modules
Python modules
 
Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Advanced Python : Decorators
Advanced Python : DecoratorsAdvanced Python : Decorators
Advanced Python : Decorators
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Exception handling and function in python
Exception handling and function in pythonException handling and function in python
Exception handling and function in python
 
Function arguments In Python
Function arguments In PythonFunction arguments In Python
Function arguments In Python
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
 
Advance OOP concepts in Python
Advance OOP concepts in PythonAdvance OOP concepts in Python
Advance OOP concepts in Python
 

Viewers also liked

Salem Witch MuseumBrochure-Katelyn Goupil
Salem Witch MuseumBrochure-Katelyn GoupilSalem Witch MuseumBrochure-Katelyn Goupil
Salem Witch MuseumBrochure-Katelyn GoupilKaren Cabral Sullivan
 
Superieur / Martel, transport diapo en rev1
Superieur / Martel, transport diapo en rev1Superieur / Martel, transport diapo en rev1
Superieur / Martel, transport diapo en rev1Peter Petropoulos
 

Viewers also liked (20)

Salem Witch MuseumBrochure-Katelyn Goupil
Salem Witch MuseumBrochure-Katelyn GoupilSalem Witch MuseumBrochure-Katelyn Goupil
Salem Witch MuseumBrochure-Katelyn Goupil
 
Guild Council - Democracy and Governance Minutes 25 03 15
Guild Council - Democracy and Governance Minutes 25 03 15Guild Council - Democracy and Governance Minutes 25 03 15
Guild Council - Democracy and Governance Minutes 25 03 15
 
Superieur / Martel, transport diapo en rev1
Superieur / Martel, transport diapo en rev1Superieur / Martel, transport diapo en rev1
Superieur / Martel, transport diapo en rev1
 
Html 5
Html 5Html 5
Html 5
 
Asp .net folders and web.config
Asp .net folders and web.configAsp .net folders and web.config
Asp .net folders and web.config
 
Introduction to mysql part 3
Introduction to mysql part 3Introduction to mysql part 3
Introduction to mysql part 3
 
jsp MySQL database connectivity
jsp MySQL database connectivityjsp MySQL database connectivity
jsp MySQL database connectivity
 
How to fix must be an instance when a foreign key is referred django python m...
How to fix must be an instance when a foreign key is referred django python m...How to fix must be an instance when a foreign key is referred django python m...
How to fix must be an instance when a foreign key is referred django python m...
 
Hiring in startups - What you should know?
Hiring in startups - What you should know?Hiring in startups - What you should know?
Hiring in startups - What you should know?
 
Jquery
JqueryJquery
Jquery
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
J query
J queryJ query
J query
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Exception
ExceptionException
Exception
 
Loops in c
Loops in cLoops in c
Loops in c
 
Multiprocessing in python
Multiprocessing in pythonMultiprocessing in python
Multiprocessing in python
 
Scope of variable
Scope of variableScope of variable
Scope of variable
 
Structures,pointers and strings in c Programming
Structures,pointers and strings in c ProgrammingStructures,pointers and strings in c Programming
Structures,pointers and strings in c Programming
 
Structure in c
Structure in cStructure in c
Structure in c
 
Introduction to c ++ part -1
Introduction to c ++   part -1Introduction to c ++   part -1
Introduction to c ++ part -1
 

Similar to Exceptions in python (20)

Python Unit II.pptx
Python Unit II.pptxPython Unit II.pptx
Python Unit II.pptx
 
06 exceptions
06 exceptions06 exceptions
06 exceptions
 
Python Session - 6
Python Session - 6Python Session - 6
Python Session - 6
 
Java - Exception Handling Concepts
Java - Exception Handling ConceptsJava - Exception Handling Concepts
Java - Exception Handling Concepts
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
Errors and exception
Errors and exceptionErrors and exception
Errors and exception
 
Exception handling in .net
Exception handling in .netException handling in .net
Exception handling in .net
 
Using spl tools in your code
Using spl tools in your codeUsing spl tools in your code
Using spl tools in your code
 
Exception handling in ASP .NET
Exception handling in ASP .NETException handling in ASP .NET
Exception handling in ASP .NET
 
Exceptions handling notes in JAVA
Exceptions handling notes in JAVAExceptions handling notes in JAVA
Exceptions handling notes in JAVA
 
Java exception
Java exception Java exception
Java exception
 
Php exceptions
Php exceptionsPhp exceptions
Php exceptions
 
Exception handling in python
Exception handling in pythonException handling in python
Exception handling in python
 
Exception handling in Java
Exception handling in JavaException handling in Java
Exception handling in Java
 
java.pptx
java.pptxjava.pptx
java.pptx
 
Introduction of exception in vb.net
Introduction of exception in vb.netIntroduction of exception in vb.net
Introduction of exception in vb.net
 
Exception handling3.pdf
Exception handling3.pdfException handling3.pdf
Exception handling3.pdf
 
Java exeception handling
Java exeception handlingJava exeception handling
Java exeception handling
 
exceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptexceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.ppt
 
Python_UNIT-I.pptx
Python_UNIT-I.pptxPython_UNIT-I.pptx
Python_UNIT-I.pptx
 

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

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

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Recently uploaded

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 

Exceptions in python

  • 1.
  • 2. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 3. EXCEPTIONS IN PYTHON SHAMEENA.V shameenavayoli@gmail.com www.facebook.com/shamee na latheef twitter.com/shameena in.linkedin.com/in/shamean 9567135569
  • 4. Introduction : Python uses exceptions to communicate errors and anomalies  exception is an object that indicates an error or anomalous condition code explicitly raise an exception by executing a raise statement.  If a program does not handle an exception, it terminates with an error traceback message
  • 5. The try Statement • The try statement provides Python's exception-handling mechanism • It is a compound statement • It can take one of two different forms: 1) try clause followed by one or more except clauses 2) A try clause followed by exactly one finally clause
  • 6. 1)try/except Syntax: try: statement(s) except [expression [, target]]: statement(s) [else: statement(s)]
  • 7. Contd…. • The body of each except clause is known as an exception handler
  • 8. 2) try/finally Syntax: try: statement(s) finally: statement(s) The finally clause establishes what is known as a clean-up handler
  • 9. Example : f = open(someFile, "w") try: do_something_with_file(f) finally: f.close( )
  • 10. Built-In Exception classes • BaseException mother of all exceptions • Exception : StandardError(base class for all built in exception) ArithmeticError FloatingPointError OverflowError ZeroDivisionError
  • 11. AttributeError (On attribute reference or assignment failure ) EnvironmentError (On error outside Python) IOError OSError WindowsError ImportError (On failure of import to find module or name.) LookupError base class for IndexError, KeyError – IndexError On out-of-range sequence subscript - KeyError On reference to a non-existent mapping (dict) key
  • 12. NameError UnBoundLocalError On reference to an unassigned local variable SyntaxError On parser encountering a syntax error – IndentationError On parser encountering an indentation syntax error --TabError On improper mixture of spaces and tabs
  • 13. Example: try: con = psycopg2.connect(database='testdb', user='shafeequemonp' ) cur = con.cursor() print "Connecting to databasen ->%s" % (con) cur.execute("""INSERT INTO tbl_user(vchr_username) VALUES(%s)""",(ins_login_base.str_name)) con.commit() except psycopg2.DatabaseError, e: if con: con.rollback() print 'Error %s' % e sys.exit(1) finally: if con: con.close() return
  • 15. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 16. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550