NeoCpp
neo4j_exception.h
1 /*
2 Apache 2.0 License
3 
4 Copyright 2018 Alex Barry
5 
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17 
18 */
19 
20 #ifndef NEO4CPP_UTILS_NEO4J_EXCEPTION_H_
21 #define NEO4CPP_UTILS_NEO4J_EXCEPTION_H_
22 
23 #include <string>
24 #include <exception>
25 
26 namespace Neocpp {
27 
29 
32 struct Neo4jException: public std::exception {
33  // An error message passed on initialization
34  std::string int_msg;
35  const char * int_msg_cstr;
36  neo4j_result_stream_t *results = NULL;
37 
38  // Create a Neo4j Exception, and store the given error message
39  inline Neo4jException(std::string msg) {
40  int_msg = "Error in Neo4j Request: " + msg;
41  int_msg_cstr = int_msg.c_str();
42  }
43 
44  inline Neo4jException(std::string msg, neo4j_result_stream_t *r) {
45  int_msg = "Error in Neo4j Request: " + msg;
46  int_msg_cstr = int_msg.c_str();
47  results = r;
48  }
49 
50  Neo4jException() {}
51  ~Neo4jException() throw() {if (results) {neo4j_close_results(results);}}
53  const char * what() const throw() {
54  return int_msg_cstr;
55  }
56 };
57 
58 } // namespace neocpp
59 
60 #endif // NEO4CPP_UTILS_NEO4J_EXCEPTION_H_
Neo4j Exception.
Definition: neo4j_exception.h:32
const char * what() const
Show the error message in readable format.
Definition: neo4j_exception.h:53
Definition: neo4j_interface.h:28