Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱

235 views

Published on

در این جلسه به بحث
Exception Handling
در پایتون پرداختیم
PySec101 Fall 2013 J6E1 By Mohammad Reza Kamalifard
Talk About:
Exception Handling in Python

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

جلسه ششم پایتون برای هکر های قانونی دوره مقدماتی پاییز ۹۲- ارائه ۱

  1. 1. Python for ethical hackers Mohammad reza Kamalifard kamalifard@datasec.ir
  2. 2. Python language essentials Module 1: Introduction to Python and Setting up an Environment for Programing 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. References SPSE securitytube training by Vivek Ramachandran SANS Python for Pentesters (SEC573) Violent python Security Power Tools python-course.eu ----------------------------http://www.python-course.eu/exception_handling.php http://www.tutorialspoint.com/python/python_exceptions.htm http://www.wilfred.me.uk/blog/2013/11/03/no-naked-excepts/
  10. 10. 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. Go to Kamalifard.ir/pysec101 to Download Slides and Course martials .

×