Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw exceptions instead of exit(1) #71

Open
kevin-keraudren opened this issue Dec 22, 2015 · 2 comments
Open

Throw exceptions instead of exit(1) #71

kevin-keraudren opened this issue Dec 22, 2015 · 2 comments

Comments

@kevin-keraudren
Copy link

exit(1) does not leave any chance to catch exceptions. It also kills interactive Python sessions.

The current code in IRTK looks like this:

https://github.com/BioMedIA/IRTK/blob/master/Modules/Image/src/irtkFileNIFTIToImage.cc#L173

    cerr << "irtkFileNIFTIToImage::ReadHeader: Number of dimensions > 5 (Number of dimensions = " << hdr.nim->dim[0] << ") \n";
    exit(1);

on the other hand the code in IRTK-LEGACY looks like this:

https://github.com/BioMedIA/IRTK/blob/master/Modules/Image/src/irtkFileNIFTIToImage.cc#L173

      stringstream msg;
      msg << "irtkFileNIFTIToImage::ReadHeader: Number of dimensions > 5 (Number of dimensions = " << hdr.nim->dim[0] << ") \n";
      cerr << msg.str();
      throw irtkException( msg.str(),
                           __FILE__,
                           __LINE__ );

Are you happy with exit(1)? Do you agree with the syntax and formating in IRTK-LEGACY or would rather have a different way of throwing exceptions?

Note that irtkExceptions are still there: https://github.com/BioMedIA/IRTK/blob/master/Modules/Common/include/irtkException.h

@kevin-keraudren
Copy link
Author

These are the two relevant commits in IRTK-LEGACY:
BioMedIA/IRTK@6fac772
BioMedIA/IRTK@c0ba69a

@ghisvail
Copy link
Member

Indeed, this is a reminder of the fact that IRTK is not as ready as we like for consumption as a public library. These exit(1) calls should disappear in favour of proper exception management such as the commits you pointed out. That being said, there are other calls to exit(1) elsewhere and I would welcome a PR that addresses all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants