OpenZWave Library  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
38 namespace OpenZWave
39 {
47  class OPENZWAVE_EXPORT OZWException : public std::runtime_error
48  {
49  public:
53  OZWEXCEPTION_INVALID_HOMEID = 100,
56  OZWEXCEPTION_SECURITY_FAILED
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  //-----------------------------------------------------------------------------
78  ExceptionType GetType() { return m_exitCode; }
79  std::string GetFile() { return m_file; }
80  uint32 GetLine() { return m_line; }
81  std::string GetMsg() { return m_msg; }
82 
83 
84  private:
85  static std::string GetExceptionText(std::string file, int line, ExceptionType exitCode, std::string msg)
86  {
87  std::stringstream ss;
88  ss << file.substr(file.find_last_of("/\\") + 1) << ":" << line;
89  switch (exitCode) {
90  case OZWEXCEPTION_OPTIONS:
91  ss << " - OptionsError (" << exitCode << ") Msg: " << msg;
92  break;
93  case OZWEXCEPTION_CONFIG:
94  ss << " - ConfigError (" << exitCode << ") Msg: " << msg;
95  break;
96  case OZWEXCEPTION_INVALID_HOMEID:
97  ss << " - InvalidHomeIDError (" << exitCode << ") Msg: " << msg;
98  break;
99  case OZWEXCEPTION_INVALID_VALUEID:
100  ss << " - InvalidValueIDError (" << exitCode << ") Msg: " << msg;
101  break;
102  case OZWEXCEPTION_CANNOT_CONVERT_VALUEID:
103  ss << " - CannotConvertValueIDError (" << exitCode << ") Msg: " << msg;
104  break;
105  case OZWEXCEPTION_SECURITY_FAILED:
106  ss << " - Security Initilization Failed (" << exitCode << ") Msg: " << msg;
107  break;
108  }
109  return ss.str();
110  }
111 
112  //-----------------------------------------------------------------------------
113  // Member variables
114  //-----------------------------------------------------------------------------
115  ExceptionType m_exitCode;
116  std::string m_file;
117  uint32 m_line;
118  std::string m_msg;
119  };
121 }
122 
123 #endif // _FatalErrorException_H
~OZWException()
Definition: OZWException.h:71
#define OPENZWAVE_EXPORT
Definition: Defs.h:52
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition: Defs.h:54
OZWException(std::string file, int line, ExceptionType exitCode, std::string msg)
Definition: OZWException.h:62
ExceptionType GetType()
Definition: OZWException.h:78
uint32 GetLine()
Definition: OZWException.h:80
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition: Defs.h:53
unsigned int uint32
Definition: Defs.h:80
std::string GetFile()
Definition: OZWException.h:79
Exception Handling Interface.
Definition: OZWException.h:47
std::string GetMsg()
Definition: OZWException.h:81
ExceptionType
Definition: OZWException.h:50