geode-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GEODE-3624) Update exceptions to more closely match standard exception interface
Date Wed, 15 Nov 2017 23:05:01 GMT

    [ https://issues.apache.org/jira/browse/GEODE-3624?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16254407#comment-16254407
] 

ASF GitHub Bot commented on GEODE-3624:
---------------------------------------

pivotal-jbarrett commented on a change in pull request #152: GEODE-3624: Update C++ client
exceptions to implement std::exception interface
URL: https://github.com/apache/geode-native/pull/152#discussion_r151277627
 
 

 ##########
 File path: cppcache/src/Exception.cpp
 ##########
 @@ -36,90 +34,29 @@ void Exception::setStackTraces(bool stackTraceEnabled) {
   s_exceptionStackTraceEnabled = stackTraceEnabled;
 }
 
-Exception::Exception(const char* msg1, const char* msg2, bool forceTrace,
-                     const std::shared_ptr<Exception>& cause)
-    : m_stack(), m_cause(cause) {
-  size_t len1 = 0;
-  if (msg1) {
-    len1 = strlen(msg1);
-  }
-  size_t len2 = 0;
-  if (msg2) {
-    len2 = strlen(msg2);
-  }
-  size_t len = len1 + len2;
-  char* msg;
-  GF_NEW(msg, char[len + 1]);
-  if (msg1) {
-    ACE_OS::memcpy(msg, msg1, len1);
-  }
-  if (msg2) {
-    ACE_OS::memcpy(msg + len1, msg2, len2);
-  }
-  msg[len] = '\0';
+Exception::Exception(const std::string& msg)
+  : Exception(msg.c_str()) {
+}
 
-  if (s_exceptionStackTraceEnabled || forceTrace) {
-    m_stack = std::make_shared<StackTrace>();
+Exception::Exception(const char* msg1)
+  : message(msg1) {
+  if (s_exceptionStackTraceEnabled/* || forceTrace*/) {
+    m_stack = std::unique_ptr<StackTrace>();
   }
-  m_message = CacheableString::createNoCopy(msg, static_cast<int32_t>(len));
 }
 
-Exception::Exception(const std::string& msg1) : Exception(msg1.c_str()) {}
+const char *Exception::what() const noexcept {
+  return message.c_str();
+}
 
-Exception::~Exception() {}
+Exception::~Exception() noexcept {}
 
 const char _exception_name_Exception[] = "apache::geode::client::Exception";
 
 const char* Exception::getName() const { return _exception_name_Exception; }
 
-const char* Exception::getMessage() const { return m_message->asChar(); }
-
-void Exception::showMessage() const {
-  printf("%s: msg = %s\n", this->getName(), m_message->asChar());
-}
-
-void Exception::printStackTrace() const {
-  showMessage();
-  if (m_stack == nullptr) {
-    fprintf(stdout, "  No stack available.\n");
-  } else {
-    m_stack->print();
-  }
-  if (m_cause != nullptr) {
-    fprintf(stdout, "Cause by exception: ");
-    m_cause->printStackTrace();
-  }
-}
-
-#ifndef _SOLARIS
-
-size_t Exception::getStackTrace(char* buffer, size_t maxLength) const {
-  size_t len = 0;
-  if (maxLength > 0) {
-    std::string traceString;
-    if (m_stack == nullptr) {
-      traceString = "  No stack available.\n";
-    } else {
-      m_stack->getString(traceString);
-    }
-    if (m_cause != nullptr) {
-      traceString += "Cause by exception: ";
-      m_cause->m_stack->getString(traceString);
-    }
-    len = ACE_OS::snprintf(buffer, maxLength, "%s", traceString.c_str());
-  }
-  return len;
-}
-
-#endif
-
-Exception::Exception(const std::shared_ptr<CacheableString>& message,
-                     const std::shared_ptr<StackTrace>& stack,
-                     const std::shared_ptr<Exception>& cause)
-    : m_message(message), m_stack(stack), m_cause(cause) {}
-
-Exception* Exception::clone() const {
-  return new Exception(m_message, m_stack, m_cause);
 
 Review comment:
   Loving all these deletes!

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Update exceptions to more closely match standard exception interface
> --------------------------------------------------------------------
>
>                 Key: GEODE-3624
>                 URL: https://issues.apache.org/jira/browse/GEODE-3624
>             Project: Geode
>          Issue Type: Improvement
>          Components: native client
>            Reporter: David Kimura
>
> Native client library should follow standard exception interface for any thrown exceptions.
 This means one less custom interface that a customer or developer needs to understand.
> {noformat}
> namespace apache {
> namespace geode {
> namespace client {
> class Exception : public std::exception {...};
> class IllegalArgumentException : public Exception {...};
> class TransactionException : public Exception {...};
> class RollbackException : public TransactionException {...};
> // NO - class IllegalArgumentException : public Exception, public
> std::invalid_argument {...};
> // NO - class IllegalArgumentException : public std::invalid_argument {...};
> // NO - class IllegalArgumentException : public Exception, public
> TransactionException {...};
> }
> }
> }
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message