OZWException.h
Go to the documentation of this file.
//-----------------------------------------------------------------------------
//
// FatalErrorException.h
//
// Exception Handling Code
//
// Copyright (c) 2014 Justin Hammond <justin@dynam.ac>
//
// SOFTWARE NOTICE AND LICENSE
//
// This file is part of OpenZWave.
//
// OpenZWave is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// OpenZWave is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
#ifndef _FatalErrorException_H
#define _FatalErrorException_H
#include <stdexcept>
#include <iostream>
#include <string>
#include <sstream>
namespace OpenZWave
{
OPENZWAVE_EXPORT_WARNINGS_OFF
class OPENZWAVE_EXPORT OZWException : public std::runtime_error
{
public:
enum ExceptionType {
OZWEXCEPTION_OPTIONS,
OZWEXCEPTION_CONFIG,
OZWEXCEPTION_INVALID_HOMEID = 100,
OZWEXCEPTION_INVALID_VALUEID,
OZWEXCEPTION_CANNOT_CONVERT_VALUEID,
OZWEXCEPTION_SECURITY_FAILED
};
//-----------------------------------------------------------------------------
// Construction
//-----------------------------------------------------------------------------
OZWException(std::string file, int line, ExceptionType exitCode, std::string msg) :
std::runtime_error(OZWException::GetExceptionText(file, line, exitCode, msg)),
m_exitCode(exitCode),
m_file(file),
m_line(line),
m_msg(msg)
{
}
~OZWException() throw()
{
}
//-----------------------------------------------------------------------------
// Accessor methods
//-----------------------------------------------------------------------------
ExceptionType GetType() { return m_exitCode; }
std::string GetFile() { return m_file; }
uint32 GetLine() { return m_line; }
std::string GetMsg() { return m_msg; }
private:
static std::string GetExceptionText(std::string file, int line, ExceptionType exitCode, std::string msg)
{
std::stringstream ss;
ss << file.substr(file.find_last_of("/\\") + 1) << ":" << line;
switch (exitCode) {
case OZWEXCEPTION_OPTIONS:
ss << " - OptionsError (" << exitCode << ") Msg: " << msg;
break;
case OZWEXCEPTION_CONFIG:
ss << " - ConfigError (" << exitCode << ") Msg: " << msg;
break;
case OZWEXCEPTION_INVALID_HOMEID:
ss << " - InvalidHomeIDError (" << exitCode << ") Msg: " << msg;
break;
case OZWEXCEPTION_INVALID_VALUEID:
ss << " - InvalidValueIDError (" << exitCode << ") Msg: " << msg;
break;
case OZWEXCEPTION_CANNOT_CONVERT_VALUEID:
ss << " - CannotConvertValueIDError (" << exitCode << ") Msg: " << msg;
break;
case OZWEXCEPTION_SECURITY_FAILED:
ss << " - Security Initilization Failed (" << exitCode << ") Msg: " << msg;
break;
}
return ss.str();
}
//-----------------------------------------------------------------------------
// Member variables
//-----------------------------------------------------------------------------
ExceptionType m_exitCode;
std::string m_file;
uint32 m_line;
std::string m_msg;
};
OPENZWAVE_EXPORT_WARNINGS_ON
}
#endif // _FatalErrorException_H
OpenZWave::OZWException::~OZWException
~OZWException()
Definition: OZWException.h:71
OpenZWave
Definition: Bitfield.h:34
OpenZWave::OZWException::OZWEXCEPTION_OPTIONS
Definition: OZWException.h:51
OPENZWAVE_EXPORT
#define OPENZWAVE_EXPORT
Definition: Defs.h:52
OPENZWAVE_EXPORT_WARNINGS_ON
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition: Defs.h:54
OpenZWave::OZWException::OZWException
OZWException(std::string file, int line, ExceptionType exitCode, std::string msg)
Definition: OZWException.h:62
OpenZWave::OZWException::GetType
ExceptionType GetType()
Definition: OZWException.h:78
OpenZWave::OZWException::OZWEXCEPTION_INVALID_VALUEID
Definition: OZWException.h:54
std
STL namespace.
OpenZWave::OZWException::GetLine
uint32 GetLine()
Definition: OZWException.h:80
OPENZWAVE_EXPORT_WARNINGS_OFF
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition: Defs.h:53
uint32
unsigned int uint32
Definition: Defs.h:80
OpenZWave::OZWException::OZWEXCEPTION_CANNOT_CONVERT_VALUEID
Definition: OZWException.h:55
OpenZWave::OZWException::GetFile
std::string GetFile()
Definition: OZWException.h:79
OpenZWave::OZWException
Exception Handling Interface.
Definition: OZWException.h:47
OpenZWave::OZWException::GetMsg
std::string GetMsg()
Definition: OZWException.h:81
OpenZWave::OZWException::ExceptionType
ExceptionType
Definition: OZWException.h:50
OpenZWave::OZWException::OZWEXCEPTION_CONFIG
Definition: OZWException.h:52