Imported Upstream version 1.0.1
[platform/upstream/iotivity.git] / service / simulator / ramlparser / raml / RamlExceptions.h
1 /******************************************************************\r
2  *\r
3  * Copyright 2015 Samsung Electronics All Rights Reserved.\r
4  *\r
5  *\r
6  *\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  *\r
19  ******************************************************************/\r
20 \r
21 /**\r
22  * @file   RamlExceptions.h\r
23  *\r
24  * @brief   This file provides exception handling while parsing RAML and Json Schema.\r
25  */\r
26 \r
27 #ifndef RAML_EXCEPTIONS_H_\r
28 #define RAML_EXCEPTIONS_H_\r
29 \r
30 #include <exception>\r
31 #include "RamlErrorCodes.h"\r
32 #include "yaml-cpp/exceptions.h"\r
33 \r
34 namespace RAML\r
35 {\r
36     /**\r
37      * @class   RamlException\r
38      * @brief   This is the base exception of all type of exception thrown from RamlParser module.\r
39      */\r
40     class RamlException : public std::exception\r
41     {\r
42         public:\r
43             /**\r
44                   * Constructor of RamlException.\r
45                   *\r
46                   * @param message - String describing the error messsage.\r
47                   */\r
48             RamlException(const std::string &message) : m_message(message) {}\r
49 \r
50             /**\r
51                   * Constructor of RamlException.\r
52                   *\r
53                   * @param mark - line and column information of exception thrown.\r
54                   * @param message - String describing the error messsage.\r
55                   */\r
56             RamlException(const YAML::Mark &mark, const std::string &message);\r
57 \r
58             /**\r
59                   * API to get error message describing exception reason.\r
60                   *\r
61                   * @return Null terminated string.\r
62                   */\r
63             virtual const char *what() const noexcept;\r
64             virtual ~RamlException() throw() {}\r
65 \r
66         private:\r
67             std::string m_message;\r
68             YAML::Mark m_mark;\r
69     };\r
70 \r
71     /**\r
72      * @class RamlParserException\r
73      * @brief This exception will be thrown to indicate Parser Exception.\r
74      */\r
75     class RamlParserException : public RamlException\r
76     {\r
77         public:\r
78             /**\r
79                   * Constructor of RamlParserException.\r
80                   *\r
81                   * @param message - String describing the error messsage.\r
82                   */\r
83             RamlParserException(const std::string &message): RamlException(message) {}\r
84 \r
85             /**\r
86                   * Constructor of RamlParserException.\r
87                   *\r
88                   * @param mark - line and column information of exception thrown.\r
89                   * @param message - String describing the error messsage.\r
90                   */\r
91             RamlParserException(const YAML::Mark &mark, const std::string &message): RamlException(mark,\r
92                         message) {}\r
93     };\r
94 \r
95     /**\r
96      * @class RamlRepresentationException\r
97      * @brief This exception will be thrown to indicate invalid Raml Representation case.\r
98      */\r
99     class RamlRepresentationException : public RamlException\r
100     {\r
101         public:\r
102             /**\r
103                   * Constructor of RamlRepresentationException.\r
104                   *\r
105                   * @param message - String describing the error messsage.\r
106                   */\r
107             RamlRepresentationException(const std::string &message): RamlException(message) {}\r
108 \r
109             /**\r
110                   * Constructor of RamlRepresentationException.\r
111                   *\r
112                   * @param mark - line and column information of exception thrown.\r
113                   * @param message - String describing the error messsage.\r
114                   */\r
115             RamlRepresentationException(const YAML::Mark &mark, const std::string &message): RamlException(mark,\r
116                         message) {}\r
117     };\r
118 \r
119     /**\r
120       * @class RamlBadFile\r
121       * @brief This exception will be thrown to indicate RAMl BadFile.\r
122       */\r
123     class RamlBadFile : public RamlException\r
124     {\r
125         public:\r
126             /**\r
127                  * Constructor of RamlBadFile.\r
128                  *\r
129                  * @param message - String describing the error messsage.\r
130                  */\r
131             RamlBadFile(const std::string &message) : RamlException(message) {}\r
132 \r
133             /**\r
134                   * Constructor of RamlBadFile.\r
135                   *\r
136                   * @param mark - line and column information of exception thrown.\r
137                   * @param message - String describing the error messsage.\r
138                   */\r
139             RamlBadFile(const YAML::Mark &mark, const std::string &message): RamlException(mark, message) {}\r
140     };\r
141     /**\r
142       * @class JsonException\r
143       * @brief This exception will be thrown to indicate invalid Json file.\r
144       */\r
145     class JsonException : public RamlException\r
146     {\r
147         public:\r
148             /**\r
149                   * Constructor of JsonException.\r
150                   *\r
151                   * @param message - String describing the error messsage.\r
152                   */\r
153             JsonException(const std::string &message) : RamlException(message) {}\r
154 \r
155     };\r
156 }\r
157 #endif\r