Mercurial > hg > orthanc
diff Plugins/Samples/Common/OrthancPluginCppWrapper.h @ 2176:fead5549aaa7
introduction of HAS_ORTHANC_EXCEPTION to avoid PluginException if not necessary
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 25 Nov 2016 12:07:36 +0100 |
parents | aa2915963531 |
children | 11420238f337 |
line wrap: on
line diff
--- a/Plugins/Samples/Common/OrthancPluginCppWrapper.h Thu Nov 24 12:58:43 2016 +0100 +++ b/Plugins/Samples/Common/OrthancPluginCppWrapper.h Fri Nov 25 12:07:36 2016 +0100 @@ -37,6 +37,11 @@ #include <boost/lexical_cast.hpp> #include <json/value.h> +#if !defined(HAS_ORTHANC_EXCEPTION) +# error The macro HAS_ORTHANC_EXCEPTION must be defined +#endif + + #if HAS_ORTHANC_EXCEPTION == 1 # include "../../../Core/OrthancException.h" #endif @@ -48,7 +53,12 @@ const char* url, const OrthancPluginHttpRequest* request); + const char* GetErrorDescription(OrthancPluginContext* context, + OrthancPluginErrorCode code); + void ThrowException(OrthancPluginErrorCode code); + +#if HAS_ORTHANC_EXCEPTION == 0 class PluginException { private: @@ -64,10 +74,14 @@ return code_; } - const char* GetErrorDescription(OrthancPluginContext* context) const; + const char* What(OrthancPluginContext* context) const + { + return ::OrthancPlugins::GetErrorDescription(context, code_); + } static void Check(OrthancPluginErrorCode code); }; +#endif class MemoryBuffer : public boost::noncopyable @@ -408,15 +422,16 @@ Callback(output, url, request); return OrthancPluginErrorCode_Success; } - catch (OrthancPlugins::PluginException& e) - { - return e.GetErrorCode(); - } #if HAS_ORTHANC_EXCEPTION == 1 catch (Orthanc::OrthancException& e) { return static_cast<OrthancPluginErrorCode>(e.GetErrorCode()); } +#else + catch (OrthancPlugins::PluginException& e) + { + return e.GetErrorCode(); + } #endif catch (boost::bad_lexical_cast&) {