From: dsarrut Date: Mon, 4 Oct 2010 07:46:34 +0000 (+0000) Subject: Exception for error management X-Git-Tag: v1.2.0~377 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=cb9d2e28489c3531d37c241fe7d8a468451c8e67;p=clitk.git Exception for error management --- diff --git a/common/clitkExceptionObject.cxx b/common/clitkExceptionObject.cxx new file mode 100644 index 0000000..8adb8a0 --- /dev/null +++ b/common/clitkExceptionObject.cxx @@ -0,0 +1,43 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ======================================================================-====*/ + +// clitk +#include "clitkExceptionObject.h" + +//-------------------------------------------------------------------- +clitk::ExceptionObject:: +ExceptionObject(const char *file, unsigned int lineNumber, const char *desc): + itk::ExceptionObject(file, lineNumber, desc) +{ + m_Message = desc; + m_LineNumber = lineNumber; + m_Filename = file; +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +const char* clitk::ExceptionObject::what() const throw() +{ + ::itk::OStringStream message; + message << "clitk::ERROR in " << m_Filename << " line " << m_LineNumber + << " : " << std::endl << "\t" << m_Message; + return message.str().c_str(); +} +//-------------------------------------------------------------------- + diff --git a/common/clitkExceptionObject.h b/common/clitkExceptionObject.h new file mode 100644 index 0000000..02f9579 --- /dev/null +++ b/common/clitkExceptionObject.h @@ -0,0 +1,59 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ======================================================================-====*/ + +#ifndef CLITKEXCEPTIONOBJECT_H +#define CLITKEXCEPTIONOBJECT_H + +// clitk +#include "clitkCommon.h" + +// itk +#include "itkExceptionObject.h" + +namespace clitk { + + //-------------------------------------------------------------------- + class ExceptionObject: public itk::ExceptionObject { + public: + ExceptionObject(const char *file, + unsigned int lineNumber=0, + const char *desc="None"); + virtual ~ExceptionObject() throw() {} + virtual const char* what() const throw(); + std::string m_Message; + int m_LineNumber; + std::string m_Filename; + }; + //-------------------------------------------------------------------- + + //-------------------------------------------------------------------- + // Largely inspired from itkExceptionMacro, but work without + // itkObject +#define clitkExceptionMacro(x) \ + { \ + ::itk::OStringStream message; \ + message << x; \ + ::clitk::ExceptionObject e_(__FILE__, __LINE__, message.str().c_str()); \ + throw e_; /* Explicit naming to work around Intel compiler bug. */ \ + } + //-------------------------------------------------------------------- + +} // end namespace clitk +//-------------------------------------------------------------------- + +#endif // CLITKEXCEPTIONOBJECT_H