MICO Platform
 All Classes Namespaces Functions Variables Friends
JnippExceptionHandling.hpp
1 #ifndef JNI_EXCEPTION_HANDLING_H
2 #define JNI_EXCEPTION_HANDLING_H
3 
4 #include <exception>
5 #include <vector>
6 #include <anno4cpp.h>
7 
8 namespace mico {
9  namespace persistence {
10  namespace jnipputil {
11 
12  static bool checkJavaExceptionNoThrow(std::vector<std::string> exceptionNames, std::string& error_msg)
13  {
14  bool failure = false;
15  error_msg.clear();
16  while (jnipp::Env::hasException()) {
17  jnipp::LocalRef<JavaLangException> ex = jnipp::Env::getException();
18  ex->printStackTrace();
19  for(auto exceptionName = exceptionNames.begin();exceptionName != exceptionNames.end(); exceptionName++)
20  if (ex->getClass()->getName()->std_str().compare(exceptionName->c_str()) == 0) {
21  error_msg += ex->getClass()->getName()->std_str() + "(msg: " + ex->getMessage()->std_str() + "), ";
22  failure = true;
23  }
24  }
25  return failure;
26  }
27 
28  static bool checkJavaExceptionNoThrow(std::string& error_msg)
29  {
30  bool failure = false;
31  error_msg.clear();
32  while (jnipp::Env::hasException()) {
33  failure = true;
34  jnipp::LocalRef<JavaLangException> ex = jnipp::Env::getException();
35  ex->printStackTrace();
36  error_msg += ex->getClass()->getName()->std_str() + "(msg: " + ex->getMessage()->std_str();
37  error_msg += "), ";
38  }
39  return failure;
40  }
41 
42  static void checkJavaExceptionThrow() {
43  std::string msg;
44 
45  if (checkJavaExceptionNoThrow(msg))
46  throw std::runtime_error(msg);
47  }
48 
49  static bool checkJavaExceptionThrow(std::vector<std::string> exceptionNames)
50  {
51  std::string msg;
52 
53  if (checkJavaExceptionNoThrow(exceptionNames, msg))
54  throw std::runtime_error(msg);
55  }
56 
57 
58 }}}
59 
60 
61 #endif
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in c...
Definition: http_client.cpp:23