COMP10001 Lecture Notes - Lecture 7: Stack Trace, Call Stack, Exception Handling

41 views1 pages
dir() lists the current namespace
-
Namespaces:
facilitates function nesting
allows functions to communicate with one another
preserve a function's local state/namespace
functions are stored on the "call stack"
-
stack trace in error message can gives hints on the cause of a bug
-
python prints the exception causing the error
-
IndexError = raised when an index is out of range
KeyError = raised when a key is not found in a dictionary
common exceptions are
-
handle exceptions by using "try: except "
-
e.g. assert type(balance) == int
use sparingly (use an explicit if statement if the result is important)
assertions ensure that inputs are of the right type
-
Exception handling:
Week 7
Monday, 23 April 2018 10:05 PM
Foundations of Computing Page 1
Unlock document

This preview shows half of the first page of the document.
Unlock all 1 pages and 3 million more documents.

Already have an account? Log in

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers