COMP10001 Lecture Notes - Lecture 7: Stack Trace, Call Stack, Exception Handling
![](https://new-preview-html.oneclass.com/R6r8MpaPXwB5NbLV3zpxmlg2z1GYy93Z/bg1.png)
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
-
Tracing functions:
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