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

Wrap lowlevel c++ string conversion exceptions with ITK exceptions. #3213

Open
hjmjohnson opened this issue Feb 20, 2022 · 2 comments
Open
Assignees
Labels
type:Design Improvement in the design of a given area

Comments

@hjmjohnson
Copy link
Member

Description

ITK was recently changed from using 'ato[ifd]' to using 'sto[ifd]' in an attempt to provide more robust error checking.

commit b9a384af33e904ae0da212ace9130632c808c6fd
Author: Hans Johnson <[email protected]>
Date:   Sat Sep 22 12:57:23 2018

    STYLE: Prefer error checked std::stoi over atoi
    
    The atoi function does not provide mechanisms for distinguishing between
    '0' and the error condion where the input can not be converted.
    
    std::stoi provides exception handling and detects when an invalid
    string attempts to be converted to an integer.
    
    atoi()
      Con: No error handling.
      Con: Handle neither hexadecimal nor octal.
    
    The use of atoi in code can cause it to be subtly broken.
    atoi makes two very big assumptions indeed:
      The string represents an integer/floating point value.
      The integer can fit into an int.

Impact analysis

The above change now introduces a data dependant throw of low-level C++ exceptions. ITK should convert these into ITK exceptions instead, with non-generic messages based on the situation.

Expected behavior

ITK generates context-specific ITK exceptions in data-induced exceptions.

Actual behavior

Default low level c++ exeptions are thrown of type

If no conversion could be performed, an [invalid_argument](https://www.cplusplus.com/invalid_argument) exception is thrown.

If the value read is out of the range of representable values by an int, an [out_of_range](https://www.cplusplus.com/out_of_range) exception is thrown.

Versions

All TIK versions after commit b9a384a

Additional Information

This change was discussed in the context of : Slicer/Slicer#6200

@hjmjohnson
Copy link
Member Author

@kian-weimer This issue would be a really nice improvement to ITK that you could take on after the wrapping stuff is figured out better.

@thewtex thewtex modified the milestones: ITK 5.4.0, ITK 6.0.0 Mar 12, 2024
@hjmjohnson
Copy link
Member Author

See: Slicer/Slicer#6200 (comment)

@hjmjohnson hjmjohnson modified the milestones: ITK 6.0.0, ITK 6.0 Beta 1 Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Design Improvement in the design of a given area
Projects
None yet
Development

No branches or pull requests

2 participants