Which exceptions i should catch and which should not in Python -
for example have program structure:
domain logic module -> settings module -> settings store backend
next part of settings module.
def load_from_json(self, json_str): try: self.load_from_dict(json.loads(json_str)) except valueerror e: raise settingsloaddataexception('error loading json')
need custom exception settingsloaddataexception here, or skip catching json.loads errors?
def load_from_json(self, json_str): self.load_from_dict(json.loads(json_str))
update.
also variant is:
def load_from_json(self, json_str): try: self.load_from_dict(json.loads(json_str)) except valueerror e: raise valueerror('error loading json')
that problem can answer. catch exceptions, or let program crash if throws exception don't handle. if vital program doesn't crash, catch exception. however, should implement recovery method then. if json doesn't load properly, can program useful without ? if can, catch exception, otherwise display error , terminate.
Comments
Post a Comment