t485.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. try:
  2. assert 1 > 10
  3. except AssertionError:
  4. print "Caught AssertionError"
  5. except:
  6. print "Did not catch AssertionError"
  7. try:
  8. print None.notAnAttribute
  9. except AttributeError:
  10. print "Caught AttributeError"
  11. except:
  12. print "Did not catch AttributeError"
  13. try:
  14. import notAModule
  15. except ImportError:
  16. print "Caught ImportError"
  17. except:
  18. print "Did not catch ImportError"
  19. try:
  20. print [0,1,2,3,4][5]
  21. except IndexError:
  22. print "Caught IndexError"
  23. except:
  24. print "Did not catch IndexError"
  25. try:
  26. print {1:2, 3:4}[5]
  27. except KeyError:
  28. print "Caught KeyError"
  29. except:
  30. print "Did not catch KeyError"
  31. try:
  32. print x
  33. except NameError:
  34. print "Caught NameError"
  35. except:
  36. print "Did not catch NameError"
  37. try:
  38. print 0.0000000000000000000000000000000000000000000000000000000000000001**-30
  39. except OverflowError:
  40. print "Caught OverflowError"
  41. except:
  42. print "Did not catch OverflowError"
  43. try:
  44. '10' / '1'
  45. except TypeError:
  46. print "Caught TypeError"
  47. except:
  48. print "Did not catch TypeError"
  49. try:
  50. print "hello".index("S")
  51. except ValueError:
  52. print "Caught ValueError"
  53. except:
  54. print "Did not catch ValueError"
  55. try:
  56. print 1 / 0
  57. except ZeroDivisionError:
  58. print "Caught ZeroDivisionError"
  59. except:
  60. print "Did not catch ZeroDivisionError"