RDK Documentation (Open Sourced RDK Components)
exception.hpp
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 
21 /**
22  * @file exception.hpp
23  * @brief This file defines Exception class for handling exceptions in device
24  * settings module.
25  */
26 
27 
28 
29 /**
30 * @defgroup devicesettings
31 * @{
32 * @defgroup ds
33 * @{
34 **/
35 
36 
37 #ifndef _DS_EXCEPTION_H_
38 #define _DS_EXCEPTION_H_
39 
40 #include <string>
41 #include <iostream>
42 #include <exception>
43 
44 namespace device{
45 
46 
47 /**
48  * @class Exception
49  * @brief This class handles exceptions occurring in DS module.
50  * @ingroup devicesettingsclass
51  */
52 class Exception : public std::exception {
53  int _err; //!< Indicates error code for the exception.
54  std::string _msg; //!< Indicates the error message.
55 
56 public:
57 
58 /**
59  * @fn Exception::Exception(const char *msg = "No Message for this exception")
60  * @brief This function is a parameterised constructor of the class Exception.
61  * It initializes the instance with the msg string passed as input parameter.
62  *
63  * @param[in] msg Message string for the exception.
64  *
65  * @return None
66  */
67  Exception(const char *msg = "No Message for this exception") throw() : _msg(msg) {
68  }
69 
70 
71 /**
72  * @fn Exception::Exception(int err, const char *msg = "No Message for this Exception")
73  * @brief This function is a parameterised constructor of the class Exception. It
74  * initializes the instance with both message string and the error code passed as
75  * input parameter.
76  *
77  * @param[in] err Indicates the error code.
78  * @param[in] msg Message string for the exception.
79  *
80  * @return None
81  */
82  Exception(int err, const char *msg = "No Message for this Exception") throw()
83  : _err(err), _msg(msg){
84  };
85 
86 
87 /**
88  * @fn Exception::getMessage()
89  * @brief This function is used to get the message string of the exception.
90  *
91  * @return _msg Message string of the exception is returned.
92  */
93  virtual const std::string & getMessage() const {
94  return _msg;
95  }
96 
97 
98 /**
99  * @fn Exception::getCode()
100  * @brief This function is used to get the error code of the exception.
101  *
102  * @return _err Error code of the exception is returned.
103  */
104  virtual int getCode() const {
105  return _err;
106  }
107 
108 
109 /**
110  * @fn Exception::what()
111  * @brief This function is overwritten to get the null terminated character sequence
112  * of the exception message.
113  *
114  * @return Returns a null terminated character sequence of the exception message.
115  */
116  virtual const char * what() const throw() {
117  return _msg.c_str();
118  }
119 
120 
121 /**
122  * @fn Exception::~Exception()
123  * @brief This function is the default destructor of Exception class.
124  *
125  * @return None
126  */
127  virtual ~Exception() throw() {};
128 };
129 
130 }
131 
132 #endif /* EXCEPTION_H_ */
133 
134 
135 /** @} */
136 /** @} */
device::Exception::what
virtual const char * what() const
This function is overwritten to get the null terminated character sequence of the exception message.
Definition: exception.hpp:116
device::Exception::~Exception
virtual ~Exception()
This function is the default destructor of Exception class.
Definition: exception.hpp:127
device::Exception::Exception
Exception(int err, const char *msg="No Message for this Exception")
This function is a parameterised constructor of the class Exception. It initializes the instance with...
Definition: exception.hpp:82
device::Exception::Exception
Exception(const char *msg="No Message for this exception")
This function is a parameterised constructor of the class Exception. It initializes the instance with...
Definition: exception.hpp:67
device::Exception::getCode
virtual int getCode() const
This function is used to get the error code of the exception.
Definition: exception.hpp:104
device::Exception::_err
int _err
Indicates error code for the exception.
Definition: exception.hpp:53
device::Exception
This class handles exceptions occurring in DS module.
Definition: exception.hpp:52
device::Exception::getMessage
virtual const std::string & getMessage() const
This function is used to get the message string of the exception.
Definition: exception.hpp:93
device::Exception::_msg
std::string _msg
Indicates the error message.
Definition: exception.hpp:54