You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I guess that thought behind the current version was to just skip the directories in which there are some problems, but from the programmatic point of view I'd like to be able to catch/except errors myself.
My suggestion is to add an argument throw_exceptions with the default value of False (for backward compatibility):
except:
if throw_exceptions:
# Rising an exception is not a default behavior. By default, e.g., conversion errors are just logged as warnings.
raise
else:
# Explicitly capturing app exceptions here to be able to continue processing.
logger.info("Unable to convert: %s" % base_filename)
traceback.print_exc()
Then, if someone would like to catch errors themselves (e.g., to count how many errors of particular kind there are) throw_exceptions would be set to True.
What do you think? I can create a PR, if you like the idea.
Hi, we found a workaround to handle/catch error information from the logger:
importloggingimportdicom2niftifromdicom2niftiimportconvert_directoryclassMyLogger(logging.Handler):
defhandle(*args):
foriteminargs:
if'Unable to convert'instr(item):
print("Catched!")
raisemy_logger=MyLogger(logging.INFO) # set out handler to catch at INFO levellogger=dicom2nifti.convert_dir.loggerlogger.addHandler(my_logger)
logger.setLevel(logging.INFO) # set main logger level to INFOtry:
convert_directory(...)
except:
do_something()
Hi,
I'd like to see an option (e.g., an argument) to throw an exception, instead of just logging it as a warning (see https://github.com/icometrix/dicom2nifti/blob/main/dicom2nifti/convert_dir.py#L89-L91).
I guess that thought behind the current version was to just skip the directories in which there are some problems, but from the programmatic point of view I'd like to be able to catch/except errors myself.
My suggestion is to add an argument
throw_exceptions
with the default value ofFalse
(for backward compatibility):https://github.com/icometrix/dicom2nifti/blob/main/dicom2nifti/convert_dir.py#L26
and then, when excepting an error:
https://github.com/icometrix/dicom2nifti/blob/main/dicom2nifti/convert_dir.py#L89-L91
Then, if someone would like to catch errors themselves (e.g., to count how many errors of particular kind there are)
throw_exceptions
would be set toTrue
.What do you think? I can create a PR, if you like the idea.
CC: @japarty
The text was updated successfully, but these errors were encountered: