اسلاید اول جلسه هفتم کلاس پایتون برای هکرهای قانونی

196 views

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
196
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

اسلاید اول جلسه هفتم کلاس پایتون برای هکرهای قانونی

  1. 1. Python for Ethical Hackers Mohammad reza Kamalifard
  2. 2. Python Language Essentials Part 7 : Exception Handling
  3. 3. Exceptions Simply put exceptions are error condtions which disrupt the normal flow of the program Python allows for a simple and elegant way to handle exceptions >>> 0/0 Traceback (most recent call last): File "<stdin>", line 1, in <module> ZeroDivisionError: integer division or modulo by zero Python Standard Exceptions http://www.tutorialspoint.com/python/standard_exceptions.htm
  4. 4. Exception Handling >>> try: ... print 0/0 ... except: ... print 'Exception Happened' ... Exception Happened >>> >>> try: ... print 100/10 ... except: ... print 'Exception' ... 10 >>>
  5. 5. else and finally >>> try: ... print 10/2 ... except: ... print 'Exception' ... else: ... print 'No Exception' ... finally: ... print 'Cleanup code always here' ... 5 No Exception Cleanup code always here >>>
  6. 6. else and finally >>> try: ... print 10/0 ... except: ... print 'Exception' ... else: ... print 'No Exception' ... finally: ... print 'Cleanup code always here' ... Exception Cleanup code always here >>>
  7. 7. >>> try: ... 10/0 ... except ZeroDivisionError: ... print 'Divided by Zero' ... Divided by Zero >>>
  8. 8. >>> try: ... 10/0 ... except Exception as err: ... print err ... integer division or modulo by zero >>> try: ... print name ... except Exception as err: ... print err ... name 'name' is not defined >>>
  9. 9. This work is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/3.0/ Copyright 2013 Mohammad reza Kamalifard. All rights reserved.

×