Handling Exceptions : Exception Handle « Exception « Python






Handling Exceptions

 

# It is possible to write programs that handle selected exceptions. Look at the following example, which prints a table of inverses of some floating point numbers:

numbers = [0.3333, 2.5, 0, 10]
for x in numbers:
   print x,
   try:
       print 1.0 / x
   except ZeroDivisionError:
       print '*** has no inverse ***'

   
  








Related examples in the same category

1.Simple exception handling exampleSimple exception handling example
2.Catch exception in a functionCatch exception in a function
3.handle multiple exceptionshandle multiple exceptions
4.Demonstrates handling exceptionsDemonstrates handling exceptions
5.Exception handlers handle Exceptions occur inside functions. Exception handlers handle Exceptions occur inside functions.