Write a Python program that demonstrates how various exceptions are caught with except Exception, exception

What will be an ideal response?

```
# Processing generic exceptions with base class Exception.

import random

# list of exceptions to raise
exceptions = [ ArithmeticError, AssertionError, AttributeError,
Exception, IndexError, KeyError, ValueError ]

for exceptionType in exceptions:

# raise each exception, with a random integer argument
try:
raise exceptionType, random.randrange( 1, 100 )

# catch exception by specifying base-class Exception type
except Exception, exceptionInstance:
print "Exception %s caught: %s" % \
( exceptionInstance.__class__, exceptionInstance )
```
Exception exceptions.ArithmeticError caught: 11
Exception exceptions.AssertionError caught: 37
Exception exceptions.AttributeError caught: 25
Exception exceptions.Exception caught: 15
Exception exceptions.IndexError caught: 88
Exception exceptions.KeyError caught: 99
Exception exceptions.ValueError caught: 10

Computer Science & Information Technology

You might also like to view...

Which type of memory is used by the computer when it starts up?

A) DDR2 B) SDRAM C) ROM D) RAM

Computer Science & Information Technology

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

1. A stack is a last-in/first-out memory structure. 2. Activation records are used to implement recursion.

Computer Science & Information Technology