Please see this implementation:
@staticmethod
def read_json_file__(file):
reports = []
try:
with open(file) as json_file:
data = json.load(json_file)
for d in data:
# Do my stuff...
try:
json_file.close()
except IOError as ex:
raise Exception(ex)
return reports
except FileNotFoundError as ex:
raise Exception('File \'{f}\' does not exist.'.format(f=ex.filename))
except Exception:
raise
I try to find the way to handle Exceptions
so I handle file open Exception
(FileNotFoundError
) and file close Exception
(IOError
) and also add Generic Exception
and raise it to caller method.
Is this correct way to handle Exception
?