![Page 1: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/1.jpg)
Exceptions
![Page 2: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/2.jpg)
Announcements
![Page 3: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/3.jpg)
Exceptions
![Page 4: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/4.jpg)
Today's Topic: Handling Errors
4
![Page 5: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/5.jpg)
Today's Topic: Handling Errors
Sometimes, computer programs behave in non-standard ways
4
![Page 6: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/6.jpg)
Today's Topic: Handling Errors
Sometimes, computer programs behave in non-standard ways
• A function receives an argument value of an improper type
4
![Page 7: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/7.jpg)
Today's Topic: Handling Errors
Sometimes, computer programs behave in non-standard ways
• A function receives an argument value of an improper type
• Some resource (such as a file) is not available
4
![Page 8: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/8.jpg)
Today's Topic: Handling Errors
Sometimes, computer programs behave in non-standard ways
• A function receives an argument value of an improper type
• Some resource (such as a file) is not available
• A network connection is lost in the middle of data transmission
4
![Page 9: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/9.jpg)
Today's Topic: Handling Errors
Sometimes, computer programs behave in non-standard ways
• A function receives an argument value of an improper type
• Some resource (such as a file) is not available
• A network connection is lost in the middle of data transmission
Grace Hopper's Notebook, 1947, Moth found in a Mark II Computer
4
![Page 10: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/10.jpg)
Exceptions
5
![Page 11: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/11.jpg)
Exceptions
A built-in mechanism in a programming language to declare and respond to exceptional conditions
5
![Page 12: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/12.jpg)
Exceptions
A built-in mechanism in a programming language to declare and respond to exceptional conditions
Python raises an exception whenever an error occurs
5
![Page 13: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/13.jpg)
Exceptions
A built-in mechanism in a programming language to declare and respond to exceptional conditions
Python raises an exception whenever an error occurs
Exceptions can be handled by the program, preventing the interpreter from halting
5
![Page 14: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/14.jpg)
Exceptions
A built-in mechanism in a programming language to declare and respond to exceptional conditions
Python raises an exception whenever an error occurs
Exceptions can be handled by the program, preventing the interpreter from halting
Unhandled exceptions will cause Python to halt execution and print a stack trace
5
![Page 15: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/15.jpg)
Exceptions
A built-in mechanism in a programming language to declare and respond to exceptional conditions
Python raises an exception whenever an error occurs
Exceptions can be handled by the program, preventing the interpreter from halting
Unhandled exceptions will cause Python to halt execution and print a stack trace
Mastering exceptions:
5
![Page 16: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/16.jpg)
Exceptions
A built-in mechanism in a programming language to declare and respond to exceptional conditions
Python raises an exception whenever an error occurs
Exceptions can be handled by the program, preventing the interpreter from halting
Unhandled exceptions will cause Python to halt execution and print a stack trace
Exceptions are objects! They have classes with constructors.
Mastering exceptions:
5
![Page 17: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/17.jpg)
Exceptions
A built-in mechanism in a programming language to declare and respond to exceptional conditions
Python raises an exception whenever an error occurs
Exceptions can be handled by the program, preventing the interpreter from halting
Unhandled exceptions will cause Python to halt execution and print a stack trace
Exceptions are objects! They have classes with constructors.
They enable non-local continuation of control
Mastering exceptions:
5
![Page 18: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/18.jpg)
Exceptions
A built-in mechanism in a programming language to declare and respond to exceptional conditions
Python raises an exception whenever an error occurs
Exceptions can be handled by the program, preventing the interpreter from halting
Unhandled exceptions will cause Python to halt execution and print a stack trace
Exceptions are objects! They have classes with constructors.
They enable non-local continuation of control
If f calls g and g calls h, exceptions can shift control from h to f without waiting for g to return.
Mastering exceptions:
5
![Page 19: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/19.jpg)
Exceptions
A built-in mechanism in a programming language to declare and respond to exceptional conditions
Python raises an exception whenever an error occurs
Exceptions can be handled by the program, preventing the interpreter from halting
Unhandled exceptions will cause Python to halt execution and print a stack trace
Exceptions are objects! They have classes with constructors.
They enable non-local continuation of control
If f calls g and g calls h, exceptions can shift control from h to f without waiting for g to return.
(Exception handling tends to be slow.)
Mastering exceptions:
5
![Page 20: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/20.jpg)
Raising Exceptions
![Page 21: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/21.jpg)
Assert Statements
Assert statements raise an exception of type AssertionError
7
![Page 22: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/22.jpg)
Assert Statements
Assert statements raise an exception of type AssertionError
assert <expression>, <string>
7
![Page 23: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/23.jpg)
Assert Statements
Assert statements raise an exception of type AssertionError
assert <expression>, <string>
Assertions are designed to be used liberally. They can be ignored to increase efficiency by running Python with the "-O" flag; "O" stands for optimized
7
![Page 24: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/24.jpg)
Assert Statements
Assert statements raise an exception of type AssertionError
assert <expression>, <string>
Assertions are designed to be used liberally. They can be ignored to increase efficiency by running Python with the "-O" flag; "O" stands for optimized
python3 -O
7
![Page 25: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/25.jpg)
Assert Statements
Assert statements raise an exception of type AssertionError
assert <expression>, <string>
Assertions are designed to be used liberally. They can be ignored to increase efficiency by running Python with the "-O" flag; "O" stands for optimized
python3 -O
Whether assertions are enabled is governed by a bool __debug__
7
![Page 26: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/26.jpg)
Assert Statements
Assert statements raise an exception of type AssertionError
assert <expression>, <string>
Assertions are designed to be used liberally. They can be ignored to increase efficiency by running Python with the "-O" flag; "O" stands for optimized
python3 -O
Whether assertions are enabled is governed by a bool __debug__
7
(Demo)
![Page 27: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/27.jpg)
Raise Statements
8
![Page 28: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/28.jpg)
Raise Statements
Exceptions are raised with a raise statement
8
![Page 29: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/29.jpg)
Raise Statements
Exceptions are raised with a raise statement
raise <expression>
8
![Page 30: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/30.jpg)
Raise Statements
Exceptions are raised with a raise statement
raise <expression>
<expression> must evaluate to a subclass of BaseException or an instance of one
8
![Page 31: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/31.jpg)
Raise Statements
Exceptions are raised with a raise statement
raise <expression>
<expression> must evaluate to a subclass of BaseException or an instance of one
Exceptions are constructed like any other object. E.g., TypeError('Bad argument!')
8
![Page 32: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/32.jpg)
Raise Statements
Exceptions are raised with a raise statement
raise <expression>
<expression> must evaluate to a subclass of BaseException or an instance of one
Exceptions are constructed like any other object. E.g., TypeError('Bad argument!')
TypeError -- A function was passed the wrong number/type of argument
8
![Page 33: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/33.jpg)
Raise Statements
Exceptions are raised with a raise statement
raise <expression>
<expression> must evaluate to a subclass of BaseException or an instance of one
Exceptions are constructed like any other object. E.g., TypeError('Bad argument!')
TypeError -- A function was passed the wrong number/type of argument
NameError -- A name wasn't found
8
![Page 34: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/34.jpg)
Raise Statements
Exceptions are raised with a raise statement
raise <expression>
<expression> must evaluate to a subclass of BaseException or an instance of one
Exceptions are constructed like any other object. E.g., TypeError('Bad argument!')
TypeError -- A function was passed the wrong number/type of argument
NameError -- A name wasn't found
KeyError -- A key wasn't found in a dictionary
8
![Page 35: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/35.jpg)
Raise Statements
Exceptions are raised with a raise statement
raise <expression>
<expression> must evaluate to a subclass of BaseException or an instance of one
Exceptions are constructed like any other object. E.g., TypeError('Bad argument!')
TypeError -- A function was passed the wrong number/type of argument
NameError -- A name wasn't found
KeyError -- A key wasn't found in a dictionary
RecursionError -- Too many recursive calls
8
![Page 36: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/36.jpg)
Raise Statements
Exceptions are raised with a raise statement
raise <expression>
<expression> must evaluate to a subclass of BaseException or an instance of one
Exceptions are constructed like any other object. E.g., TypeError('Bad argument!')
TypeError -- A function was passed the wrong number/type of argument
NameError -- A name wasn't found
KeyError -- A key wasn't found in a dictionary
RecursionError -- Too many recursive calls
8
(Demo)
![Page 37: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/37.jpg)
Try Statements
![Page 38: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/38.jpg)
Try Statements
10
![Page 39: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/39.jpg)
Try Statements
Try statements handle exceptions
10
![Page 40: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/40.jpg)
Try Statements
Try statements handle exceptions
try: <try suite> except <exception class> as <name>: <except suite> ...
10
![Page 41: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/41.jpg)
Try Statements
Try statements handle exceptions
try: <try suite> except <exception class> as <name>: <except suite> ...
Execution rule:
10
![Page 42: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/42.jpg)
Try Statements
Try statements handle exceptions
try: <try suite> except <exception class> as <name>: <except suite> ...
Execution rule:
The <try suite> is executed first
10
![Page 43: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/43.jpg)
Try Statements
Try statements handle exceptions
try: <try suite> except <exception class> as <name>: <except suite> ...
Execution rule:
The <try suite> is executed first
If, during the course of executing the <try suite>, an exception is raised that is not handled otherwise, and
10
![Page 44: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/44.jpg)
Try Statements
Try statements handle exceptions
try: <try suite> except <exception class> as <name>: <except suite> ...
Execution rule:
The <try suite> is executed first
If, during the course of executing the <try suite>, an exception is raised that is not handled otherwise, and
If the class of the exception inherits from <exception class>, then
10
![Page 45: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/45.jpg)
Try Statements
Try statements handle exceptions
try: <try suite> except <exception class> as <name>: <except suite> ...
Execution rule:
The <try suite> is executed first
If, during the course of executing the <try suite>, an exception is raised that is not handled otherwise, and
If the class of the exception inherits from <exception class>, then
The <except suite> is executed, with <name> bound to the exception
10
![Page 46: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/46.jpg)
Handling Exceptions
11
![Page 47: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/47.jpg)
Handling Exceptions
Exception handling can prevent a program from terminating
11
![Page 48: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/48.jpg)
Handling Exceptions
Exception handling can prevent a program from terminating
>>> try:
11
![Page 49: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/49.jpg)
Handling Exceptions
Exception handling can prevent a program from terminating
>>> try: x = 1/0
11
![Page 50: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/50.jpg)
Handling Exceptions
Exception handling can prevent a program from terminating
>>> try: x = 1/0 except ZeroDivisionError as e:
11
![Page 51: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/51.jpg)
Handling Exceptions
Exception handling can prevent a program from terminating
>>> try: x = 1/0 except ZeroDivisionError as e: print('handling a', type(e))
11
![Page 52: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/52.jpg)
Handling Exceptions
Exception handling can prevent a program from terminating
>>> try: x = 1/0 except ZeroDivisionError as e: print('handling a', type(e)) x = 0
11
![Page 53: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/53.jpg)
Handling Exceptions
Exception handling can prevent a program from terminating
>>> try: x = 1/0 except ZeroDivisionError as e: print('handling a', type(e)) x = 0
handling a <class 'ZeroDivisionError'>
11
![Page 54: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/54.jpg)
Handling Exceptions
Exception handling can prevent a program from terminating
>>> try: x = 1/0 except ZeroDivisionError as e: print('handling a', type(e)) x = 0
handling a <class 'ZeroDivisionError'>>>> x0
11
![Page 55: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/55.jpg)
Handling Exceptions
Exception handling can prevent a program from terminating
>>> try: x = 1/0 except ZeroDivisionError as e: print('handling a', type(e)) x = 0
handling a <class 'ZeroDivisionError'>>>> x0
Multiple try statements: Control jumps to the except suite of the most recent try statement that handles that type of exception
11
![Page 56: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/56.jpg)
Handling Exceptions
Exception handling can prevent a program from terminating
>>> try: x = 1/0 except ZeroDivisionError as e: print('handling a', type(e)) x = 0
handling a <class 'ZeroDivisionError'>>>> x0
Multiple try statements: Control jumps to the except suite of the most recent try statement that handles that type of exception
11
(Demo)
![Page 57: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/57.jpg)
WWPD: What Would Python Display?
How will the Python interpreter respond?
12
![Page 58: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/58.jpg)
WWPD: What Would Python Display?
How will the Python interpreter respond?
12
![Page 59: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/59.jpg)
WWPD: What Would Python Display?
How will the Python interpreter respond?
def invert(x): inverse = 1/x # Raises a ZeroDivisionError if x is 0 print('Never printed if x is 0') return inverse
def invert_safe(x): try: return invert(x) except ZeroDivisionError as e: return str(e)
12
![Page 60: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/60.jpg)
WWPD: What Would Python Display?
How will the Python interpreter respond?
>>> invert_safe(1/0)
def invert(x): inverse = 1/x # Raises a ZeroDivisionError if x is 0 print('Never printed if x is 0') return inverse
def invert_safe(x): try: return invert(x) except ZeroDivisionError as e: return str(e)
12
![Page 61: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/61.jpg)
WWPD: What Would Python Display?
How will the Python interpreter respond?
>>> invert_safe(1/0)>>> try:
def invert(x): inverse = 1/x # Raises a ZeroDivisionError if x is 0 print('Never printed if x is 0') return inverse
def invert_safe(x): try: return invert(x) except ZeroDivisionError as e: return str(e)
12
![Page 62: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/62.jpg)
WWPD: What Would Python Display?
How will the Python interpreter respond?
>>> invert_safe(1/0)>>> try:... invert_safe(0)
def invert(x): inverse = 1/x # Raises a ZeroDivisionError if x is 0 print('Never printed if x is 0') return inverse
def invert_safe(x): try: return invert(x) except ZeroDivisionError as e: return str(e)
12
![Page 63: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/63.jpg)
WWPD: What Would Python Display?
How will the Python interpreter respond?
>>> invert_safe(1/0)>>> try:... invert_safe(0)... except ZeroDivisionError as e:
def invert(x): inverse = 1/x # Raises a ZeroDivisionError if x is 0 print('Never printed if x is 0') return inverse
def invert_safe(x): try: return invert(x) except ZeroDivisionError as e: return str(e)
12
![Page 64: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/64.jpg)
WWPD: What Would Python Display?
How will the Python interpreter respond?
>>> invert_safe(1/0)>>> try:... invert_safe(0)... except ZeroDivisionError as e:... print('Hello!')
def invert(x): inverse = 1/x # Raises a ZeroDivisionError if x is 0 print('Never printed if x is 0') return inverse
def invert_safe(x): try: return invert(x) except ZeroDivisionError as e: return str(e)
12
![Page 65: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/65.jpg)
WWPD: What Would Python Display?
How will the Python interpreter respond?
>>> invert_safe(1/0)>>> try:... invert_safe(0)... except ZeroDivisionError as e:... print('Hello!')>>> inverrrrt_safe(1/0)
def invert(x): inverse = 1/x # Raises a ZeroDivisionError if x is 0 print('Never printed if x is 0') return inverse
def invert_safe(x): try: return invert(x) except ZeroDivisionError as e: return str(e)
12
![Page 66: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/66.jpg)
Example: Reduce
![Page 67: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/67.jpg)
Reducing a Sequence to a Value
14
![Page 68: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/68.jpg)
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
![Page 69: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/69.jpg)
f is ... a two-argument function
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
![Page 70: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/70.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
![Page 71: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/71.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
![Page 72: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/72.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
![Page 73: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/73.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow
![Page 74: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/74.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2
![Page 75: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/75.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2
[
[
![Page 76: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/76.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2 1
[
[
![Page 77: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/77.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2 1
2
[
[
![Page 78: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/78.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2 1
pow 2
[
[
![Page 79: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/79.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2 1
pow 2 2
[
[
![Page 80: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/80.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2 1
pow 2 2
4
[
[
![Page 81: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/81.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2 1
pow
pow 2 2
4
[
[
![Page 82: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/82.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2 1
pow
pow 2 2
4 3
[
[
![Page 83: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/83.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2 1
pow
pow 2 2
4 3
64
[
[
![Page 84: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/84.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2 1
pow
pow
pow
2 2
4 3
64
[
[
![Page 85: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/85.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2 1
pow
pow
pow
2 2
4 3
64 4
[
[
![Page 86: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/86.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2 1
pow
pow
pow
2 2
4 3
64 4
16,777,216
[
[
![Page 87: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/87.jpg)
f is ... a two-argument functions is ... a sequence of values that can be the second argumentinitial is ... a value that can be the first argument
Reducing a Sequence to a Value
def reduce(f, s, initial): """Combine elements of s pairwise using f, starting with initial.
E.g., reduce(mul, [2, 4, 8], 1) is equivalent to mul(mul(mul(1, 2), 4), 8).
>>> reduce(mul, [2, 4, 8], 1) 64 """
14
reduce(pow, [1, 2, 3, 4], 2)
pow 2 1
pow
pow
pow
2 2
4 3
64 4
16,777,216
[
[
(Demo)
![Page 88: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/88.jpg)
Environment Diagrams Review
![Page 89: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/89.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
Return Value
Return Value
Return Value
![Page 90: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/90.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
Return Value
Return Value
Return Value
[parent=G]
![Page 91: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/91.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
[parent=G]
![Page 92: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/92.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear func abs(...) [parent=G]
Return Value
Return Value
Return Value
[parent=G]
![Page 93: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/93.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear func abs(...) [parent=G]
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
[parent=G]
![Page 94: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/94.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear func abs(...) [parent=G]
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
[parent=G]
![Page 95: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/95.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear func abs(...) [parent=G]
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
[parent=G]
![Page 96: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/96.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear func abs(...) [parent=G]
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal [parent=f1]
[parent=G]
![Page 97: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/97.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear func abs(...) [parent=G]
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal [parent=f1]
berk 2
[parent=G]
![Page 98: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/98.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear func abs(...) [parent=G]
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
[parent=G]
![Page 99: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/99.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear func abs(...) [parent=G]
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
[parent=G]
![Page 100: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/100.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear func abs(...) [parent=G]
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
[parent=G]
![Page 101: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/101.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
[parent=G]
![Page 102: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/102.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
[parent=G]
![Page 103: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/103.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
[parent=G]
![Page 104: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/104.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
[parent=G]
![Page 105: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/105.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
[parent=G]
![Page 106: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/106.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
[parent=G]
![Page 107: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/107.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
[parent=G]
![Page 108: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/108.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal
[parent=G]
![Page 109: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/109.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
[parent=G]
![Page 110: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/110.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
2berk
[parent=G]
![Page 111: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/111.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
2berk
[parent=G]
![Page 112: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/112.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
2berk
[parent=G]
![Page 113: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/113.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
2berk
f4: λ
[parent=G]
![Page 114: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/114.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
2berk
f4: λ [parent=f2]
[parent=G]
![Page 115: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/115.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
2berk
f4: λ [parent=f2]
ley 2
[parent=G]
![Page 116: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/116.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
2berk
f4: λ [parent=f2]
ley 2
[parent=G]
![Page 117: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/117.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
2berk
f4: λ [parent=f2]
ley 2
0
[parent=G]
![Page 118: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/118.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
2berk list10
3 1
f4: λ [parent=f2]
ley 2
0
[parent=G]
![Page 119: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/119.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
2berk list10
3 1
f4: λ [parent=f2]
list10
2
ley 2
0
[parent=G]
![Page 120: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/120.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
2berk list10
3 1
f4: λ [parent=f2]
list10
2
ley 2
0
[parent=G]
![Page 121: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/121.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
2berk list10
3 1
f4: λ [parent=f2]
list10
2
ley 2
0
[parent=G]
![Page 122: Exceptions - University of California, BerkeleyToday's Topic: Handling Errors Sometimes, computer programs behave in non-standard ways •A function receives an argument value of an](https://reader036.vdocuments.us/reader036/viewer/2022070111/604e2373bd05a472080504ad/html5/thumbnails/122.jpg)
Go Bears!
16
def oski(bear):
def cal(berk):
nonlocal bear
if bear(berk) == 0:
return [berk+1, berk-1]
bear = lambda ley: berk-ley
return [berk, cal(berk)]
return cal(2)
oski(abs)
Return Value
Global frameoski func oski(bear)[parent=G]
f1: oski
bear
Return Value
Return Value
Return Value
cal func cal(berk) [parent=f1]
f2: cal
func λ(ley) [parent=f2]
[parent=f1]
berk 2
f3: cal [parent=f1]
2berk list10
3 1
f4: λ [parent=f2]
list10
2
ley 2
0
[parent=G]
[2, [3, 1]]