Write a Python program that shows that a function with its own try statement does not have to catch every possible exception that occurs within the try suite. Some exceptions can slip through to, and be handled in, other scopes.

What will be an ideal response?


```
# Letting outer frames catch exceptions.

import random

# continuously gets integers from user until divide by zero
def mainloop():

while 1:

# get integer from user
try:
userChoice = int( raw_input( "\nNumerator: " ) )
print "Result:", userChoice / random.randrange( -1, 2 )

# user did not input an integer
except ValueError:
print "Not an integer!"

# call mainloop and catch ZeroDivisionError
try:
mainloop()
except ZeroDivisionError:
print "Divided by zero"
```
Numerator: 5
Result: 5
Numerator: 4
Result: -4
Numerator: 3
Result: Divided by zero

Computer Science & Information Technology

You might also like to view...

The concrete classes that implement the List interface are

A) AbstractList, AbstractSequentialList, and List B) LinkedList, ArrayList, and AbstractList C) LinkedList and ArrayList D) None of the above

Computer Science & Information Technology

The first three frames of a button are known as ____________________.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

The type of card you have will determine the type of card reader/writer needed.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Which of the following forms of e-commerceis more likely to offer a more customized product offering?

A. Business-to-government (B2G) e-commerce B. Business-to-business (B2B) e-commerce C. Consumer-to-consumer (C2C) e-commerce D. ?Business-to-consumer (B2C) e-commerce

Computer Science & Information Technology