Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

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

در این جلسه به بحث
Exception Handling
در پایتون پرداختیم

Mohammad reza Kamalifard

November 18, 2013
Tweet

More Decks by Mohammad reza Kamalifard

Other Decks in Education

Transcript

  1. Python language essentials Module 1: Introduction to Python and Setting

    up an Environment for Programing Part 7 : Exception Handling
  2. 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
  3. Exception Handling >>> try: ... print 0/0 ... except: ...

    print 'Exception Happened' ... Exception Happened >>> >>> try: ... print 100/10 ... except: ... print 'Exception' ... 10 >>>
  4. 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 >>>
  5. 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 >>>
  6. >>> 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 >>>
  7. 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/
  8. 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 .