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