Skip to content

Commit bf82b3c

Browse files
N-Dekkerdzenanz
authored andcommitted
STYLE: ExceptionObject may assume that std::string::c_str() never throws
Simplified the implementation of `ExceptionObject`, based on C++11 `std::string::c_str()` being marked `noexcept`. Removed the internal `ExceptionObject::ExceptionData::m_WhatPointer` pointer, that was introduced with commit 8bfd356, "BUG: fixed issue 0007094: itk::ExceptionObject should never cause a crash. Removed ExceptionObject::UpdateWhat(), ...", 28 May 2008.
1 parent 0402e50 commit bf82b3c

File tree

1 file changed

+1
-8
lines changed

1 file changed

+1
-8
lines changed

Modules/Core/Common/src/itkExceptionObject.cxx

+1-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class ExceptionObject::ExceptionData : public ReferenceCounterInterface
4747
m_What = m_File;
4848
m_What += loc.str();
4949
m_What += m_Description;
50-
m_WhatPointer = m_What.c_str();
5150
}
5251

5352
private:
@@ -61,7 +60,6 @@ class ExceptionObject::ExceptionData : public ReferenceCounterInterface
6160
const std::string m_File;
6261
const unsigned int m_Line;
6362
std::string m_What;
64-
const char * m_WhatPointer;
6563
};
6664

6765
/** \class ExceptionObject::ReferenceCountedExceptionData
@@ -262,21 +260,18 @@ ExceptionObject::SetDescription(const char * s)
262260
const char *
263261
ExceptionObject::GetLocation() const
264262
{
265-
// Note: std::string::c_str() might throw an exception.
266263
return m_ExceptionData.IsNull() ? "" : this->GetExceptionData()->m_Location.c_str();
267264
}
268265

269266
const char *
270267
ExceptionObject::GetDescription() const
271268
{
272-
// Note: std::string::c_str() might throw an exception.
273269
return m_ExceptionData.IsNull() ? "" : this->GetExceptionData()->m_Description.c_str();
274270
}
275271

276272
const char *
277273
ExceptionObject::GetFile() const
278274
{
279-
// Note: std::string::c_str() might throw an exception.
280275
return m_ExceptionData.IsNull() ? "" : this->GetExceptionData()->m_File.c_str();
281276
}
282277

@@ -291,9 +286,7 @@ ExceptionObject::what() const noexcept
291286
{
292287
const ExceptionData * const thisData = this->GetExceptionData();
293288

294-
// Note: m_What.c_str() wouldn't be safe, because c_str() might throw an
295-
// exception.
296-
return thisData ? thisData->m_WhatPointer : "ExceptionObject";
289+
return thisData ? thisData->m_What.c_str() : "ExceptionObject";
297290
}
298291

299292
void

0 commit comments

Comments
 (0)