Pim Schellart | 5a7d17f | 2016-06-17 17:35:59 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | from __future__ import print_function |
| 3 | import sys |
| 4 | sys.path.append('.') |
| 5 | |
| 6 | import example |
| 7 | |
| 8 | print("Can we catch a MyException?") |
| 9 | try: |
| 10 | example.throws1() |
| 11 | except example.MyException as e: |
| 12 | print(e.__class__.__name__, ":", e) |
| 13 | print("") |
| 14 | |
| 15 | print("Can we translate to standard Python exceptions?") |
| 16 | try: |
| 17 | example.throws2() |
| 18 | except Exception as e: |
| 19 | print(e.__class__.__name__, ":", e) |
| 20 | print("") |
| 21 | |
| 22 | print("Can we handle unknown exceptions?") |
| 23 | try: |
| 24 | example.throws3() |
| 25 | except Exception as e: |
| 26 | print(e.__class__.__name__, ":", e) |
| 27 | print("") |
| 28 | |
| 29 | print("Can we delegate to another handler by rethrowing?") |
| 30 | try: |
| 31 | example.throws4() |
| 32 | except example.MyException as e: |
| 33 | print(e.__class__.__name__, ":", e) |
| 34 | print("") |
| 35 | |
| 36 | print("Can we fall-through to the default handler?") |
| 37 | try: |
| 38 | example.throws_logic_error() |
| 39 | except Exception as e: |
| 40 | print(e.__class__.__name__, ":", e) |
| 41 | print("") |
| 42 | |