Commit fd6a1994 authored by Victor Poughon's avatar Victor Poughon

Merge branch '513-exceptions' into 'develop'

Remove more c_str with itk::ExceptionObject string constructor

See merge request !199
parents e7fb0df2 55905018
......@@ -129,7 +129,7 @@ namespace otb
{ \
std::ostringstream message; \
message << "otb::ERROR Unknown error while running " << # command << " (catch(...) )"; \
::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
::itk::ExceptionObject e_(__FILE__, __LINE__, message.str(), ITK_LOCATION); \
throw e_; \
} \
std::cout << " Checking valid command " << # command " ok." << std::endl; \
......@@ -160,14 +160,14 @@ namespace otb
{ \
std::ostringstream message; \
message << "otb::ERROR Unknown error while running " << # command << " (catch(...) )"; \
::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
::itk::ExceptionObject e_(__FILE__, __LINE__, message.str(), ITK_LOCATION); \
throw e_; \
} \
if (result == 1) \
{ \
std::ostringstream message; \
message << "otb::ERROR: " << # command << " should be throwing an exception."; \
::itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
::itk::ExceptionObject e_(__FILE__, __LINE__, message.str(), ITK_LOCATION); \
throw e_; \
} \
}
......
......@@ -140,7 +140,7 @@ ObjectListToObjectListFilter<TInputList, TOutputList>
std::ostringstream message;
message << "itk::ERROR: " << this->GetNameOfClass()
<< "(" << this << "): " << "Subclass should override this method!!!";
itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION);
itk::ExceptionObject e_(__FILE__, __LINE__, message.str(), ITK_LOCATION);
throw e_;
}
......
......@@ -265,7 +265,7 @@ ImageToPointSetFilter<TInputImage, TOutputPointSet>
std::ostringstream message;
message << "itk::ERROR: " << this->GetNameOfClass()
<< "(" << this << "): " << "Subclass should override this method!!!";
itk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION);
itk::ExceptionObject e_(__FILE__, __LINE__, message.str(), ITK_LOCATION);
throw e_;
}
......
......@@ -377,7 +377,7 @@ WaveletFilterBank<TInputImage, TOutputImage, TWaveletOperator, Wavelet::FORWARD>
std::ostringstream msg;
msg << "Output number 1<<" << dir << " = " << (1 << dir) << " not allocated\n";
msg << "Number of expected outputs " << this->GetNumberOfOutputs() << "\n";
throw itk::ExceptionObject(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
throw itk::ExceptionObject(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
}
itk::ProgressReporter reporter(this, threadId,
......
......@@ -39,7 +39,7 @@ WaveletGenerator<TMotherWaveletOperator>
std::ostringstream msg;
msg << "The mother wavelet ID " << TMotherWaveletOperator;
msg << " is unknown or has to be implemented...\n";
throw itk::ExceptionObject(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
throw itk::ExceptionObject(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
return "Unknown";
}
......@@ -52,7 +52,7 @@ WaveletGenerator<TMotherWaveletOperator>
std::ostringstream msg;
msg << "The mother wavelet ID " << TMotherWaveletOperator;
msg << " is unknown or has to be implemented...\n";
throw itk::ExceptionObject(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
throw itk::ExceptionObject(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
}
template <Wavelet::Wavelet TMotherWaveletOperator>
......@@ -63,7 +63,7 @@ WaveletGenerator<TMotherWaveletOperator>
std::ostringstream msg;
msg << "The mother wavelet ID " << TMotherWaveletOperator;
msg << " is unknown or has to be implemented (check the hxx file)...\n";
throw itk::ExceptionObject(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
throw itk::ExceptionObject(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
}
/**
......
......@@ -54,7 +54,7 @@ ImageSeriesFileReader<TImage, TInternalImage>
std::ostringstream msg;
msg << "Something wrong... Check the template definition of this class in the program...\n";
msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
}
......@@ -100,7 +100,7 @@ ImageSeriesFileReader<Image<TPixel, 2>, Image<TInternalPixel, 2> >
std::ostringstream msg;
msg << "Unable to handle multicomponent file from Image<> class\n";
msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
}
......@@ -109,7 +109,7 @@ ImageSeriesFileReader<Image<TPixel, 2>, Image<TInternalPixel, 2> >
std::ostringstream msg;
msg << "Unable to handle given band reading from multicomponent file with Image<> class\n";
msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
}
return;
......@@ -190,7 +190,7 @@ ImageSeriesFileReader<Image<TPixel, 2>, VectorImage<TInternalPixel, 2> >
std::ostringstream msg;
msg << "Unable to handle multicomponent file from Image<> class as output\n";
msg << "\"ENVI META FILE\" FileName: " << this->m_FileName << "\n";
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
}
return;
......
......@@ -49,6 +49,11 @@ public:
const char* message = "Error in IO",
const char* loc = "Unknown") :
itk::ExceptionObject(file, line, message, loc) {}
ImageSeriesFileReaderException(const std::string& file, unsigned int line,
const std::string& message = "Error in IO",
const std::string& loc = "Unknown") :
itk::ExceptionObject(file, line, message, loc) {}
};
/** \class ImageSeriesFileReaderBase
......
......@@ -117,7 +117,7 @@ ImageSeriesFileReaderBase<TImage, TInternalImage>
inputFile.close();
std::ostringstream msg;
msg << "The file " << m_FileName << " is not a \"ENVI META FILE\" format\n";
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
return;
}
......@@ -128,7 +128,7 @@ ImageSeriesFileReaderBase<TImage, TInternalImage>
inputFile.close();
std::ostringstream msg;
msg << "The file " << m_FileName << " is not a \"ENVI META FILE\" format\n";
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
return;
}
......@@ -139,7 +139,7 @@ ImageSeriesFileReaderBase<TImage, TInternalImage>
inputFile.close();
std::ostringstream msg;
msg << "The file " << m_FileName << " is not a \"ENVI META FILE\" format\n";
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
return;
}
......@@ -171,7 +171,7 @@ ImageSeriesFileReaderBase<TImage, TInternalImage>
std::ostringstream msg;
msg << "Unable to read image files in the \"ENVI META FILE\" file \n";
msg << "FileName: " << m_FileName << "\n";
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
return;
}
......@@ -205,7 +205,7 @@ ImageSeriesFileReaderBase<TImage, TInternalImage>
std::ostringstream msg;
msg << "Unable to read the number of bands in the images in the \"ENVI META FILE\" file \n";
msg << "FileName: " << m_FileName << "\n";
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
return;
}
......@@ -277,7 +277,7 @@ ImageSeriesFileReaderBase<TImage, TInternalImage>
msg << "Unable to read image region in the \"ENVI META FILE\" file \n";
msg << "FileName : " << m_FileName << "\n";
msg << "ImageName: " << imageFileName << "\n";
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
return;
}
......@@ -294,7 +294,7 @@ ImageSeriesFileReaderBase<TImage, TInternalImage>
msg << "Unable to read image region selection in the \"ENVI META FILE\" file \n";
msg << "FileName : " << m_FileName << "\n";
msg << "ImageName: " << imageFileName << "\n";
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
return;
}
......@@ -338,7 +338,7 @@ ImageSeriesFileReaderBase<TImage, TInternalImage>
std::ostringstream msg;
msg << "Something wrong... Check the template definition of this class in the program...\n";
msg << "\"ENVI META FILE\" FileName: " << m_FileName << "\n";
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
}
......@@ -464,7 +464,7 @@ ImageSeriesFileReaderBase<TImage, TInternalImage>
std::ostringstream msg;
msg << "The file couldn't be opened for reading. "
<< std::endl << "Filename: " << file << std::endl;
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
ImageSeriesFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
return;
}
......
......@@ -54,6 +54,13 @@ public:
itk::ExceptionObject(file, line, message, loc)
{
}
VectorDataFileReaderException(const std::string& file, unsigned int line,
const std::string& message = "Error in IO",
const char* loc = "Unknown") :
itk::ExceptionObject(file, line, message, loc)
{
}
};
/** \brief Data source that reads vector data from a single file.
......
......@@ -93,7 +93,7 @@ VectorDataFileReader<TOutputVectorData>
msg << "The file couldn't be opened for reading. "
<< std::endl << "Filename: " << this->m_FileName
<< std::endl;
VectorDataFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
VectorDataFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
return;
......@@ -174,7 +174,7 @@ VectorDataFileReader<TOutputVectorData>
msg << " You probably failed to set a file suffix, or" << std::endl;
msg << " set the suffix to an unsupported type." << std::endl;
}
VectorDataFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
VectorDataFileReaderException e(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
throw e;
return;
}
......
......@@ -51,7 +51,7 @@ MarkovRandomFieldFilter<TInputImage, TClassifiedImage>
std::ostringstream msg;
msg << "Input image dimension: " << InputImageDimension << " != output image dimension: " <<
ClassifiedImageDimension;
throw itk::ExceptionObject(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
throw itk::ExceptionObject(__FILE__, __LINE__, msg.str(), ITK_LOCATION);
}
m_InputImageNeighborhoodRadius.Fill(m_NeighborhoodRadius);
// m_MRFNeighborhoodWeight.resize(0);
......
......@@ -61,9 +61,13 @@ public:
const char* loc = "Unknown");
/** Constructor. */
ApplicationException(const std::string &file, unsigned int line,
ApplicationException(const std::string& file, unsigned int line,
const char* message = "Application error.",
const char* loc = "Unknown");
ApplicationException(const std::string& file, unsigned int line,
const std::string& message = "Application error.",
const std::string& loc = "Unknown");
};
namespace Wrapper
......
......@@ -30,7 +30,7 @@
{ \
std::ostringstream message; \
message << "otb::ApplicationException " x; \
::otb::ApplicationException e_(__FILE__, __LINE__, message.str().c_str(), ITK_LOCATION); \
::otb::ApplicationException e_(__FILE__, __LINE__, message.str(), ITK_LOCATION); \
throw e_; /* Explicit naming to work around Intel compiler bug. */ \
} \
}
......
......@@ -64,6 +64,12 @@ ExceptionObject(file, line, message, loc)
{
}
ApplicationException::ApplicationException(const std::string &file, unsigned int line,
const std::string& message, const std::string& loc) :
ExceptionObject(file, line, message, loc)
{
}
namespace Wrapper
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment