OpenZWave Library 1.6.1914
OZWException.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2//
3// FatalErrorException.h
4//
5// Exception Handling Code
6//
7// Copyright (c) 2014 Justin Hammond <justin@dynam.ac>
8//
9// SOFTWARE NOTICE AND LICENSE
10//
11// This file is part of OpenZWave.
12//
13// OpenZWave is free software: you can redistribute it and/or modify
14// it under the terms of the GNU Lesser General Public License as published
15// by the Free Software Foundation, either version 3 of the License,
16// or (at your option) any later version.
17//
18// OpenZWave is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU Lesser General Public License for more details.
22//
23// You should have received a copy of the GNU Lesser General Public License
24// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
25//
26//-----------------------------------------------------------------------------
27
28#ifndef _FatalErrorException_H
29#define _FatalErrorException_H
30
31#include <stdexcept>
32#include <iostream>
33#include <string>
34#include <sstream>
35
36namespace OpenZWave
37{
44class OPENZWAVE_EXPORT OZWException : public std::runtime_error
45{
46 public:
48 {
51 OZWEXCEPTION_INVALID_HOMEID = 100,
55 OZWEXCEPTION_INVALID_NODEID
56 };
57
58 //-----------------------------------------------------------------------------
59 // Construction
60 //-----------------------------------------------------------------------------
61 OZWException(std::string file, int line, ExceptionType exitCode, std::string msg) :
62 std::runtime_error(OZWException::GetExceptionText(file, line, exitCode, msg)),
63 m_exitCode(exitCode),
64 m_file(file),
65 m_line(line),
66 m_msg(msg)
67 {
68 }
69
70 ~OZWException() throw()
71 {
72 }
73
74 //-----------------------------------------------------------------------------
75 // Accessor methods
76 //-----------------------------------------------------------------------------
78 { return m_exitCode;}
79 std::string GetFile()
80 { return m_file;}
82 { return m_line;}
83 std::string GetMsg()
84 { return m_msg;}
85
86 private:
87 static std::string GetExceptionText(std::string file, int line, ExceptionType exitCode, std::string msg)
88 {
89 std::stringstream ss;
90 ss << file.substr(file.find_last_of("/\\") + 1) << ":" << line;
91 switch (exitCode)
92 {
93 case OZWEXCEPTION_OPTIONS:
94 ss << " - OptionsError (" << exitCode << ") Msg: " << msg;
95 break;
96 case OZWEXCEPTION_CONFIG:
97 ss << " - ConfigError (" << exitCode << ") Msg: " << msg;
98 break;
99 case OZWEXCEPTION_INVALID_HOMEID:
100 ss << " - InvalidHomeIDError (" << exitCode << ") Msg: " << msg;
101 break;
102 case OZWEXCEPTION_INVALID_VALUEID:
103 ss << " - InvalidValueIDError (" << exitCode << ") Msg: " << msg;
104 break;
105 case OZWEXCEPTION_CANNOT_CONVERT_VALUEID:
106 ss << " - CannotConvertValueIDError (" << exitCode << ") Msg: " << msg;
107 break;
108 case OZWEXCEPTION_SECURITY_FAILED:
109 ss << " - Security Initialization Failed (" << exitCode << ") Msg: " << msg;
110 break;
111 case OZWEXCEPTION_INVALID_NODEID:
112 ss << " - InvalidNodeIDError (" << exitCode << ") Msg: " << msg;
113 break;
114 }
115 return ss.str();
116 }
117
118 //-----------------------------------------------------------------------------
119 // Member variables
120 //-----------------------------------------------------------------------------
121 ExceptionType m_exitCode;
122 std::string m_file;
123 uint32 m_line;
124 std::string m_msg;
125};
126}
127
128#endif // _FatalErrorException_H
unsigned int uint32
Definition: Defs.h:91
#define OPENZWAVE_EXPORT
Definition: Defs.h:52
Exception Handling Interface.
Definition: OZWException.h:45
std::string GetFile()
Definition: OZWException.h:79
uint32 GetLine()
Definition: OZWException.h:81
OZWException(std::string file, int line, ExceptionType exitCode, std::string msg)
Definition: OZWException.h:61
ExceptionType
Definition: OZWException.h:48
@ OZWEXCEPTION_OPTIONS
Definition: OZWException.h:49
@ OZWEXCEPTION_INVALID_VALUEID
Definition: OZWException.h:52
@ OZWEXCEPTION_CANNOT_CONVERT_VALUEID
Definition: OZWException.h:53
@ OZWEXCEPTION_SECURITY_FAILED
Definition: OZWException.h:54
@ OZWEXCEPTION_CONFIG
Definition: OZWException.h:50
~OZWException()
Definition: OZWException.h:70
ExceptionType GetType()
Definition: OZWException.h:77
std::string GetMsg()
Definition: OZWException.h:83
Definition: Bitfield.cpp:31
STL namespace.