Wrap context manager callback in exception handler.