class with_test(): def __enter__(self): print('With Enter') return 'Enter Reference' def __exit__(self, *args): print('With Exit:', args) if args[0]: raiseprint('* Try and catch statement outside with *')try: with with_test() as f: print('Inside with code:', f) raise Exception('Testing Exception') print('After with code:', f)except Exception as e: print('Exception handling with exception:', e, f)print('\n* Try and catch statement inside with *')with with_test() as f: try: print('Inside with code:', f) raise Exception('Testing Exception') except Exception as e: print('Exception handling:', e, f)"""* Try and catch statement outside with *With EnterInside with code: Enter ReferenceWith Exit: (<class 'Exception'>, Exception('Testing Exception',), <traceback object at 0x000002CE6B64F908>)Exception handling with exception: Testing Exception Enter Reference* Try and catch statement inside with *With EnterInside with code: Enter ReferenceException handling: Testing Exception Enter ReferenceWith Exit: (None, None, None)"""2019-02-14