OpenZWave Library 1.6.0
Loading...
Searching...
No Matches
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
36
37
38namespace OpenZWave
39{
47 class OPENZWAVE_EXPORT OZWException : public std::runtime_error
48 {
49 public:
59
60 //-----------------------------------------------------------------------------
61 // Construction
62 //-----------------------------------------------------------------------------
63 OZWException(std::string file, int line, ExceptionType exitCode, std::string msg) :
64 std::runtime_error(OZWException::GetExceptionText(file, line, exitCode, msg)),
65 m_exitCode(exitCode),
66 m_file(file),
67 m_line(line),
68 m_msg(msg)
69 {
70 }
71
72 ~OZWException() throw()
73 {
74 }
75
76 //-----------------------------------------------------------------------------
77 // Accessor methods
78 //-----------------------------------------------------------------------------
79 ExceptionType GetType() { return m_exitCode; }
80 std::string GetFile() { return m_file; }
81 uint32 GetLine() { return m_line; }
82 std::string GetMsg() { return m_msg; }
83
84
85 private:
86 static std::string GetExceptionText(std::string file, int line, ExceptionType exitCode, std::string msg)
87 {
88 std::stringstream ss;
89 ss << file.substr(file.find_last_of("/\\") + 1) << ":" << line;
90 switch (exitCode) {
91 case OZWEXCEPTION_OPTIONS:
92 ss << " - OptionsError (" << exitCode << ") Msg: " << msg;
93 break;
94 case OZWEXCEPTION_CONFIG:
95 ss << " - ConfigError (" << exitCode << ") Msg: " << msg;
96 break;
97 case OZWEXCEPTION_INVALID_HOMEID:
98 ss << " - InvalidHomeIDError (" << exitCode << ") Msg: " << msg;
99 break;
100 case OZWEXCEPTION_INVALID_VALUEID:
101 ss << " - InvalidValueIDError (" << exitCode << ") Msg: " << msg;
102 break;
103 case OZWEXCEPTION_CANNOT_CONVERT_VALUEID:
104 ss << " - CannotConvertValueIDError (" << exitCode << ") Msg: " << msg;
105 break;
106 case OZWEXCEPTION_SECURITY_FAILED:
107 ss << " - Security Initialization Failed (" << exitCode << ") Msg: " << msg;
108 break;
109 case OZWEXCEPTION_INVALID_NODEID:
110 ss << " - InvalidNodeIDError (" << exitCode << ") Msg: " << msg;
111 break;
112 }
113 return ss.str();
114 }
115
116 //-----------------------------------------------------------------------------
117 // Member variables
118 //-----------------------------------------------------------------------------
119 ExceptionType m_exitCode;
120 std::string m_file;
121 uint32 m_line;
122 std::string m_msg;
123 };
125}
126
127#endif // _FatalErrorException_H
unsigned int uint32
Definition Defs.h:95
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition Defs.h:53
#define OPENZWAVE_EXPORT
Definition Defs.h:51
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition Defs.h:52
Exception Handling Interface.
Definition OZWException.h:48
std::string GetFile()
Definition OZWException.h:80
uint32 GetLine()
Definition OZWException.h:81
OZWException(std::string file, int line, ExceptionType exitCode, std::string msg)
Definition OZWException.h:63
ExceptionType
Definition OZWException.h:50
@ OZWEXCEPTION_OPTIONS
Definition OZWException.h:51
@ OZWEXCEPTION_INVALID_VALUEID
Definition OZWException.h:54
@ OZWEXCEPTION_CANNOT_CONVERT_VALUEID
Definition OZWException.h:55
@ OZWEXCEPTION_SECURITY_FAILED
Definition OZWException.h:56
@ OZWEXCEPTION_CONFIG
Definition OZWException.h:52
~OZWException()
Definition OZWException.h:72
ExceptionType GetType()
Definition OZWException.h:79
std::string GetMsg()
Definition OZWException.h:82
Definition Bitfield.h:35
STL namespace.