Skip to content

Commit

Permalink
COMP: Avoid "message" naming conflicts when calling an exception macro
Browse files Browse the repository at this point in the history
Replaced the very general term "message" inside the definition of
`itkSpecializedMessageExceptionMacro` by a much more specific
identifier, "exceptionDescriptionOutputStringStream", to avoid naming
conflicts in user code.

Removed the unnecessary `std::string{ ... }` construction for the result
of `std::ostringstream::str()`, as it is an `std::string` already.
  • Loading branch information
N-Dekker authored and dzenanz committed Mar 15, 2021
1 parent 396c2a1 commit 3d35e43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Modules/Core/Common/include/itkMacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,10 @@ OutputWindowDisplayDebugText(const char *);

#define itkSpecializedMessageExceptionMacro(ExceptionType, x) \
{ \
std::ostringstream message; \
message << "ITK ERROR: " x; \
std::ostringstream exceptionDescriptionOutputStringStream; \
exceptionDescriptionOutputStringStream << "ITK ERROR: " x; \
throw ::itk::ExceptionType( \
std::string{ __FILE__ }, __LINE__, std::string{ message.str() }, std::string{ ITK_LOCATION }); \
std::string{ __FILE__ }, __LINE__, exceptionDescriptionOutputStringStream.str(), std::string{ ITK_LOCATION }); \
} \
ITK_MACROEND_NOOP_STATEMENT

Expand Down
10 changes: 5 additions & 5 deletions Modules/Core/Common/test/itkExceptionObjectGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ TEST(ExceptionObject, TestDescriptionFromExceptionMacro)
itkTypeMacroNoParent(TestClass);

void
CallExceptionMacro(const std::string & testMessage) const
CallExceptionMacro(const std::string & message) const
{
itkExceptionMacro(<< testMessage);
itkExceptionMacro(<< message);
}
};

const std::string testMessage = "test message";
const std::string message = "test message";
const TestClass testObject{};

try
{
testObject.CallExceptionMacro(testMessage);
testObject.CallExceptionMacro(message);
}
catch (const itk::ExceptionObject & exceptionObject)
{
const char * const actualDescription = exceptionObject.GetDescription();
ASSERT_NE(actualDescription, nullptr);

std::ostringstream expectedDescription;
expectedDescription << "ITK ERROR: " << testObject.GetNameOfClass() << "(" << &testObject << "): " << testMessage;
expectedDescription << "ITK ERROR: " << testObject.GetNameOfClass() << "(" << &testObject << "): " << message;

EXPECT_EQ(actualDescription, expectedDescription.str());
}
Expand Down

0 comments on commit 3d35e43

Please sign in to comment.