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

Make ITK exceptions and their tests specific #983

jhlegarreta opened this issue Jun 1, 2019 · 0 comments


None yet
2 participants
Copy link

commented Jun 1, 2019


ITK exceptions are largely non-specific, i.e. a general itkExceptionMacro can loosely used to throw virtually any type of exception. Making exceptions be more specific, including the messages, would make the toolkit more consistent.

At the same time, the TRY_EXPECT_EXCEPTION macro is non-specific, meaning that it expects the statement to throw an exception, whichever the exception is. When writing such a statement in a test, the programmer generally expects a specific exception to be caught, i.e. an exception with a known message to be thrown. However, if the code is not designed correctly or hides a bug, the statement may well catch an exception, but one that has been thrown elsewhere/is different from the one expected. The test or macro would work correctly, because it does not check the exception type (or better, the source of the exception, or both).

PR #511 uncovered such a situation.

Impact analysis

Having non-specific exceptions provides a flexible framework, but may hide bugs. Also, if there is no way to check the exception type and/or the class that threw it, when expecting an exception, any other exception thrown in the call stack may be considered as a valid exception

Expected behavior

Creating a specific set of exceptions and enhancing the TRY_EXPECT_EXCEPTION to accept the class and exception type would help in making the code more consistent, and robust.


TRY_EXPECT_EXCEPTION( filter->Update(), FilterClass, ExceptionType );

Actual behavior

Current exception checking:

TRY_EXPECT_EXCEPTION( filter->Update() );



Additional Information


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.