Skip to content
Snippets Groups Projects
Exception.cpp 8 KiB
Newer Older
Nick Draper's avatar
Nick Draper committed
#include <iostream>
#include <sstream>
Stuart Ansell's avatar
Stuart Ansell committed
#include <string>
#include "MantidKernel/Exception.h"

Nick Draper's avatar
Nick Draper committed

namespace Mantid
{
namespace Kernel
Stuart Ansell's avatar
Stuart Ansell committed
{
namespace Exception
{
Nick Draper's avatar
Nick Draper committed
//-------------------------
// FileError
//-------------------------
/** Constructor
	@param Desc :: Function description
	@param FName :: Filename
Nick Draper's avatar
Nick Draper committed
*/
FileError::FileError(const std::string& Desc,const std::string& FName) :
std::runtime_error(Desc),fileName(FName)
Nick Draper's avatar
Nick Draper committed
{
	outMessage = std::string(std::runtime_error::what()) + " in " + fileName;
}
Nick Draper's avatar
Nick Draper committed
/// Copy constructor
FileError::FileError(const FileError& A) :
  std::runtime_error(A),fileName(A.fileName)
{}

/** Writes out the range and limits
	@returns a char array of foramtted error information
*/
const char* FileError::what() const throw()
{
Nick Draper's avatar
Nick Draper committed
	return outMessage.c_str();
Stuart Ansell's avatar
Stuart Ansell committed
}

Nick Draper's avatar
Nick Draper committed
//-------------------------
// NotImplementedError
//-------------------------
/** Constructor
Nick Draper's avatar
Nick Draper committed
*/
NotImplementedError::NotImplementedError(const std::string& Desc) :
std::logic_error(Desc)
{}
Nick Draper's avatar
Nick Draper committed
/// Copy constructor
NotImplementedError::NotImplementedError(const NotImplementedError& A) :
  std::logic_error(A)
{}

/** Writes out the range and limits
	@returns a char array of foramtted error information
*/
const char* NotImplementedError::what() const throw()
{
Nick Draper's avatar
Nick Draper committed
  return std::logic_error::what();
Stuart Ansell's avatar
Stuart Ansell committed
}

Nick Draper's avatar
Nick Draper committed
//-------------------------
// NotFoundError
//-------------------------
/** Constructor
	@param Desc :: Function description
	@param ObjectName :: The name of the search object
Nick Draper's avatar
Nick Draper committed
*/
NotFoundError::NotFoundError(const std::string& Desc,const std::string& ObjectName) :
std::runtime_error(Desc),objectName(ObjectName)
Nick Draper's avatar
Nick Draper committed
	outMessage = std::string(std::runtime_error::what()) + " search object " + objectName;
}
Nick Draper's avatar
Nick Draper committed

/** Constructor
	@param Desc :: Function description
	@param ObjectNum :: The integer search object
Nick Draper's avatar
Nick Draper committed
*/
NotFoundError::NotFoundError(const std::string& Desc,const int& ObjectNum) :
std::runtime_error(Desc)
  std::stringstream ss;
  std::string obName;
  ss << ObjectNum;
Nick Draper's avatar
Nick Draper committed
  ss >> obName;
	outMessage = std::string(std::runtime_error::what()) + " search object " + obName;
}
Nick Draper's avatar
Nick Draper committed
/// Copy constructor
NotFoundError::NotFoundError(const NotFoundError& A) :
  std::runtime_error(A),objectName(A.objectName)
{}

/** Writes out the range and limits
	@returns a char array of foramtted error information
*/
const char* NotFoundError::what() const throw()
{
Nick Draper's avatar
Nick Draper committed
	return outMessage.c_str();
Stuart Ansell's avatar
Stuart Ansell committed
}

Nick Draper's avatar
Nick Draper committed
//-------------------------
// ExistsError
//-------------------------
/** Constructor
	@param Desc :: Function description
	@param ObjectName :: The name of the search object
Nick Draper's avatar
Nick Draper committed
*/
ExistsError::ExistsError(const std::string& Desc,const std::string& ObjectName) :
std::runtime_error(Desc),objectName(ObjectName)
Nick Draper's avatar
Nick Draper committed
{
	outMessage = std::string(std::runtime_error::what()) + " search object " + objectName;
}
Nick Draper's avatar
Nick Draper committed
/// Copy constructor
ExistsError::ExistsError(const ExistsError& A) :
  std::runtime_error(A),objectName(A.objectName)
{}

/** Writes out the range and limits
	@returns a char array of foramtted error information
*/
const char* ExistsError::what() const throw()
{
Nick Draper's avatar
Nick Draper committed
	return outMessage.c_str();
Stuart Ansell's avatar
Stuart Ansell committed
}

//-------------------------
// AbsObjMethod
//-------------------------
/** Constructor
	@param ObjectName :: The name of the search object
Stuart Ansell's avatar
Stuart Ansell committed
*/
AbsObjMethod::AbsObjMethod(const std::string& ObjectName) :
  std::runtime_error(""),objectName(ObjectName)
{
  outMessage = std::string("AbsObjMethod object: ") + objectName;
}
Stuart Ansell's avatar
Stuart Ansell committed
/// Copy constructor
AbsObjMethod::AbsObjMethod(const AbsObjMethod& A) :
  std::runtime_error(A),objectName(A.objectName)
{}

/** Writes out the range and limits
	@returns a char array of foramtted error information
*/
const char* AbsObjMethod::what() const throw()
{
  return outMessage.c_str();
}

//-------------------------
// InstrumentDefinitionError
//-------------------------
/** Constructor
	@param Desc :: Function description
	@param ObjectName :: The name of the search object
*/
InstrumentDefinitionError::InstrumentDefinitionError(const std::string& Desc,const std::string& ObjectName) :
std::runtime_error(Desc),objectName(ObjectName)
{
	outMessage = std::string(std::runtime_error::what()) + " search object " 
    + objectName + ". See http://www.mantidproject.org/IDF for IDF syntax.";
*/
InstrumentDefinitionError::InstrumentDefinitionError(const std::string& Desc) :
std::runtime_error(Desc)
{
	outMessage = std::string(std::runtime_error::what());
}

/// Copy constructor
InstrumentDefinitionError::InstrumentDefinitionError(const InstrumentDefinitionError& A) :
  std::runtime_error(A),objectName(A.objectName)
{}

/** Writes out the range and limits
	@returns a char array of foramtted error information
*/
const char* InstrumentDefinitionError::what() const throw()
{
	return outMessage.c_str();
Stuart Ansell's avatar
Stuart Ansell committed
}


Sri Nagella's avatar
Sri Nagella committed
//-------------------------
// OpenGLError
//-------------------------
/** Constructor
	@param Desc :: Function description
	@param ObjectName :: The name of the search object
Sri Nagella's avatar
Sri Nagella committed
*/
OpenGLError::OpenGLError(const std::string& Desc,const std::string& ObjectName) :
std::runtime_error(Desc),objectName(ObjectName)
{
	outMessage = std::string(std::runtime_error::what()) + " rendering " + objectName;
}

/** Constructor
Sri Nagella's avatar
Sri Nagella committed
*/
OpenGLError::OpenGLError(const std::string& Desc) :
std::runtime_error(Desc)
{
	outMessage = std::string(std::runtime_error::what());
}

/// Copy constructor
OpenGLError::OpenGLError(const OpenGLError& A) :
  std::runtime_error(A),objectName(A.objectName)
{}

/** Writes out the range and limits
	@returns a char array of foramtted error information
*/
const char* OpenGLError::what() const throw()
{
	return outMessage.c_str();
}


Nick Draper's avatar
Nick Draper committed
//-------------------------
// MisMatch
//-------------------------

Nick Draper's avatar
Nick Draper committed
MisMatch<T>::MisMatch(const T& A,const T& B,const std::string& Place) :
  std::runtime_error(Place),Aval(A),Bval(B)
Nick Draper's avatar
Nick Draper committed
    Constructor store two mismatched items
    @param A :: Item to store
    @param B :: Item to store
    @param Place :: Reason/Code item for error
Nick Draper's avatar
Nick Draper committed
  */
{}

Nick Draper's avatar
Nick Draper committed
MisMatch<T>::MisMatch(const MisMatch<T>& A) :
  std::runtime_error(A.what()),Aval(A.Aval),Bval(A.Bval)
Nick Draper's avatar
Nick Draper committed
    Copy Constructor
Nick Draper's avatar
Nick Draper committed
  */
{}

Nick Draper's avatar
Nick Draper committed
const char*
MisMatch<T>::what() const throw()
Nick Draper's avatar
Nick Draper committed
    Writes out the two mismatched items
Nick Draper's avatar
Nick Draper committed
  */
{
  std::stringstream cx;
  cx<<std::runtime_error::what()<<" Item A!=B "<<Aval<<
    " "<<Bval<<" ";
  return cx.str().c_str();
}

/// \cond TEMPLATE
template class DLLExport MisMatch<int>;
/// \endcond TEMPLATE

//-------------------------
Nick Draper's avatar
Nick Draper committed
// Index Error class
Nick Draper's avatar
Nick Draper committed
  Constructor
  @param V :: Value of index
  @param B :: Maximum value
  @param Place :: Location of Error
Nick Draper's avatar
Nick Draper committed
*/
IndexError::IndexError(const int V,const int B, const std::string& Place) :
  std::runtime_error(Place),Val(V),maxVal(B)
Nick Draper's avatar
Nick Draper committed
{}

Nick Draper's avatar
Nick Draper committed
  Copy Constructor
Nick Draper's avatar
Nick Draper committed
*/
IndexError::IndexError(const IndexError& A) :
  std::runtime_error(A),Val(A.Val),maxVal(A.maxVal)
{}

Nick Draper's avatar
Nick Draper committed
    Writes out the range and limits
Nick Draper's avatar
Nick Draper committed
    @return the error string
Nick Draper's avatar
Nick Draper committed
  */
Nick Draper's avatar
Nick Draper committed
const char* IndexError::what() const throw()
Nick Draper's avatar
Nick Draper committed
{
  std::stringstream cx;
  cx<<"IndexError:"<<std::runtime_error::what()<<" "<<Val<<" :: 0 <==> "<<maxVal;
  return cx.str().c_str();
}

//-------------------------
// NullPointerException class
//-------------------------
Nick Draper's avatar
Nick Draper committed

 *  @param place ::      The class & function where the exception occurred
 *  @param objectName :: The name of the pointer
 */
NullPointerException::NullPointerException(const std::string& place, const std::string& objectName) :
  std::runtime_error(place),
  outMessage("Attempt to dereference zero pointer ("+objectName+") in function "+place)
{}
Nick Draper's avatar
Nick Draper committed

 *  @param rhs :: The NullPointerException to copy
 */
NullPointerException::NullPointerException(const NullPointerException& rhs) :
  std::runtime_error(rhs), outMessage(rhs.outMessage)
{}

const char* NullPointerException::what() const throw()
{
  return outMessage.c_str();
}
Nick Draper's avatar
Nick Draper committed

Stuart Ansell's avatar
Stuart Ansell committed
} // namespace Exception
} // namespace Kernel
} // namespace Mantid