(filename)
| 49 | |
| 50 | print("Example 1") |
| 51 | def try_finally_example(filename): |
| 52 | print("* Opening file") |
| 53 | handle = open(filename, encoding="utf-8") # May raise OSError |
| 54 | try: |
| 55 | print("* Reading data") |
| 56 | return handle.read() # May raise UnicodeDecodeError |
| 57 | finally: |
| 58 | print("* Calling close()") |
| 59 | handle.close() # Always runs after try block |
| 60 | |
| 61 | |
| 62 | print("Example 2") |
no test coverage detected