Skip to content

Throw exceptions instead of exit(1) #71

@kevin-keraudren

Description

@kevin-keraudren

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions