Skip to content

Commit

Permalink
Added a new exception type for errors happened during file parsing.
Browse files Browse the repository at this point in the history
Refs #7772
  • Loading branch information
arturbekasov committed Aug 20, 2013
1 parent 51b26d0 commit 43de19f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
34 changes: 33 additions & 1 deletion Code/Mantid/Framework/Kernel/inc/MantidKernel/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ namespace Kernel
<li><b>std::range_error</b> - Thrown to indicate range errors in internal computations.</li>
<li><b>std::overflow_error</b> - Thrown to indicate arithmetic overflow.</li>
<li><b>std::underflow_error</b> - Thrown to indicate arithmetic underflow.</li>
<li><b>FileError</b> - Thrown to indicate errors with file operations.</li>
<li>
<b>FileError</b> - Thrown to indicate errors with file operations.
<ul>
<li><b>ParseError</b> - Thrown to indicate errors when parsing a file.</li>
</ul>
</li>
<li><b>NotFoundError</b> - Thrown to indicate that an item was not found in a collection.</li>
<li><b>ExistsError</b> - Thrown to indicate that an item was is already found in a collection.</li>
<li><b>InstrumentDefinitionError</b> - Thrown to indicate a problem with the instrument definition.</li>
Expand Down Expand Up @@ -98,6 +103,33 @@ class MANTID_KERNEL_DLL FileError : public std::runtime_error
const char* what() const throw();
};

/// Records the filename, the description of failure and the line on which it happened
class MANTID_KERNEL_DLL ParseError : public FileError
{
private:
/// Number of the line where the error occured
const int m_lineNumber;
/// The message returned by what()
std::string m_outMessage;

public:
/**
* Constructor
* @param desc :: Error description
* @param fileName :: Filename where happened
* @param lineNumber :: Number of the line where error happened
*/
ParseError(const std::string& desc, const std::string& fileName, const int& lineNumber);
/// Copy constructor
ParseError(const ParseError& A);
/// Assignment operator
ParseError& operator=(const ParseError& A);
/// Destructor
~ParseError() throw() {}

const char* what() const throw();
};

/// Marks code as not implemented yet.
class MANTID_KERNEL_DLL NotImplementedError : public std::logic_error
{
Expand Down
20 changes: 20 additions & 0 deletions Code/Mantid/Framework/Kernel/src/Exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ const char* FileError::what() const throw()
return outMessage.c_str();
}

//-------------------------
// ParseError
//-------------------------
ParseError::ParseError(const std::string& desc, const std::string& fileName, const int& lineNumber)
: FileError(desc, fileName), m_lineNumber(lineNumber)
{
std::stringstream ss;
ss << FileError::what() << " on line " << m_lineNumber;
m_outMessage = ss.str();
}

ParseError::ParseError(const ParseError& A)
: FileError(A), m_lineNumber(A.m_lineNumber)
{}

const char* ParseError::what() const throw()
{
return m_outMessage.c_str();
}

//-------------------------
// NotImplementedError
//-------------------------
Expand Down

0 comments on commit 43de19f

Please sign in to comment.