Your SlideShare is downloading. ×
  • Like
Exceptions
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply
Published

Exception handling

Exception handling

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
88
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. 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
  • 2. Exception• An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the programs instructions.• Handling an exception: • Defend your program by placing the suspicious code in a try: block. After the try: block, include an except: statement, followed by a block of code which handles the problem as elegantly as possible.
  • 3. Syntax:Exception handlingtry: operationsexcept ExceptionI: If there is ExceptionI, then execute this block.except ExceptionII:If there is ExceptionII, then execute this block.else: If there is no exception then execute this block
  • 4. Exampletry:fh = open("testfile", "w")fh.write("This is my test file for exception handling!!")except IOError:print "Error: cant find file or read data"else:print "Written content in the file successfully"fh.close()
  • 5. User-Defined Exceptions:class Networkerror(RuntimeError):def __init__(self, arg): self.args = argtry:raise Networkerror("Bad hostname") except Networkerror,e: print e.args
  • 6. 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
  • 7. Contact Us
  • 8. Contact Us