11. Exception Handling - 11 EXCEPTION HANDLING Rocky K C...

Info icon This preview shows pages 1–8. Sign up to view the full content.

11. EXCEPTION HANDLING Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Objectives To understand the idea of exception handling and be able to write simple exception handling code that catches standard Python run-time errors.
Image of page 2
Exception Handling Various error messages can occur when executing Python programs. Such errors are called exceptions. An exception is a value (object) that is raised (“thrown”) signaling that an unexpected, or “exceptional,” situation has occurred. Python contains a predefined set of exceptions referred to as standard exceptions.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

EXERCISE 11.1 Try List = [1,2,3]; List[3] file = open("unknown.py", "r") x = 3 + "4" in = 10 int("10.4") import maths
Image of page 4
Standard exceptions in Python Source: Charles Dierbach. 2013. Introduction to Computer Science Using Python. Wiley. See for all built-in exceptions
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

EXERCISE 11.2 Find a Python file that has functions. Try to make an error inside the function and observe the error messages reported to you.
Image of page 6
Propagation of Raised Exceptions Source: Charles Dierbach. 2013. Introduction to Computer Science Using Python.
Image of page 7

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Image of page 8
This is the end of the preview. Sign up to access the rest of the document.
  • Fall '16
  • Rocky Chiang
  • Control flow

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern