From 958647601758a9cbd78082a76c3583c3ce9e852e Mon Sep 17 00:00:00 2001 From: "Charles E. Rolke" Date: Tue, 2 Nov 2010 20:50:54 +0000 Subject: QPID-2923 Qpid Messaging .NET Binding fails to translate exceptions from C++ to .NET This checkin moves code out of class constructor member initialization and puts it into try-catch blocks. Any SEH Exceptions thrown by the C++ Messaging libraries are caught and re-thrown as .NET exceptions. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1030209 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/bindings/qpid/dotnet/src/Address.cpp | 152 ++++++++++++++++++++++++++----- 1 file changed, 131 insertions(+), 21 deletions(-) (limited to 'cpp/bindings/qpid/dotnet/src/Address.cpp') diff --git a/cpp/bindings/qpid/dotnet/src/Address.cpp b/cpp/bindings/qpid/dotnet/src/Address.cpp index 6d23136cbd..b78eb8243e 100644 --- a/cpp/bindings/qpid/dotnet/src/Address.cpp +++ b/cpp/bindings/qpid/dotnet/src/Address.cpp @@ -29,6 +29,7 @@ #include "QpidMarshal.h" #include "QpidTypeCheck.h" #include "TypeTranslator.h" +#include "QpidException.h" namespace Org { namespace Apache { @@ -40,28 +41,74 @@ namespace Messaging { /// // Create empty - Address::Address() : - addressp(new ::qpid::messaging::Address(QpidMarshal::ToNative(""))) + Address::Address() { + System::Exception ^ newException = nullptr; + + try + { + addressp = new ::qpid::messaging::Address(QpidMarshal::ToNative("")); + } + catch (const ::qpid::types::Exception & error) + { + String ^ errmsg = gcnew String(error.what()); + newException = gcnew QpidException(errmsg); + } + + if (newException != nullptr) + { + throw newException; + } } // Create string address - Address::Address(System::String ^ address) : - addressp(new ::qpid::messaging::Address(QpidMarshal::ToNative(address))) + Address::Address(System::String ^ address) { + System::Exception ^ newException = nullptr; + + try + { + addressp = new ::qpid::messaging::Address(QpidMarshal::ToNative(address)); + } + catch (const ::qpid::types::Exception & error) + { + String ^ errmsg = gcnew String(error.what()); + newException = gcnew QpidException(errmsg); + } + + if (newException != nullptr) + { + throw newException; + } } // Create with options Address::Address(System::String ^ name, System::String ^ subject, System::Collections::Generic::Dictionary< - System::String ^, System::Object ^> ^ options) : - addressp(new ::qpid::messaging::Address()) + System::String ^, System::Object ^> ^ options) { - Name = name; - Subject = subject; - Options = options; - Type = ""; + System::Exception ^ newException = nullptr; + + try + { + addressp = new ::qpid::messaging::Address(); + + Name = name; + Subject = subject; + Options = options; + Type = ""; + } + catch (const ::qpid::types::Exception & error) + { + String ^ errmsg = gcnew String(error.what()); + newException = gcnew QpidException(errmsg); + } + + if (newException != nullptr) + { + throw newException; + } } // Create with options and type @@ -69,26 +116,72 @@ namespace Messaging { System::String ^ subject, System::Collections::Generic::Dictionary< System::String ^, System::Object ^> ^ options, - System::String ^ type) : - addressp(new ::qpid::messaging::Address()) + System::String ^ type) { - Name = name; - Subject = subject; - Options = options; - Type = type; + System::Exception ^ newException = nullptr; + + try + { + addressp = new ::qpid::messaging::Address(); + + Name = name; + Subject = subject; + Options = options; + Type = type; + } + catch (const ::qpid::types::Exception & error) + { + String ^ errmsg = gcnew String(error.what()); + newException = gcnew QpidException(errmsg); + } + + if (newException != nullptr) + { + throw newException; + } } // copy constructor Address::Address(const Address ^ address) - : addressp(new ::qpid::messaging::Address( - *(const_cast
(address)->NativeAddress))) { + System::Exception ^ newException = nullptr; + + try + { + addressp = new ::qpid::messaging::Address( + *(const_cast
(address)->NativeAddress)); + } + catch (const ::qpid::types::Exception & error) + { + String ^ errmsg = gcnew String(error.what()); + newException = gcnew QpidException(errmsg); + } + + if (newException != nullptr) + { + throw newException; + } } // unmanaged clone - Address::Address(const ::qpid::messaging::Address & addrp) : - addressp(new ::qpid::messaging::Address(addrp)) + Address::Address(const ::qpid::messaging::Address & addrp) { + System::Exception ^ newException = nullptr; + + try + { + addressp = new ::qpid::messaging::Address(addrp); + } + catch (const ::qpid::types::Exception & error) + { + String ^ errmsg = gcnew String(error.what()); + newException = gcnew QpidException(errmsg); + } + + if (newException != nullptr) + { + throw newException; + } } // Destructor @@ -121,6 +214,23 @@ namespace Messaging { // System::String ^ Address::ToStr() { - return gcnew System::String(addressp->str().c_str()); + System::String ^ result = nullptr; + System::Exception ^ newException = nullptr; + + try + { + result = gcnew System::String(addressp->str().c_str()); + } + catch (const ::qpid::types::Exception & error) + { + String ^ errmsg = gcnew String(error.what()); + newException = gcnew QpidException(errmsg); + } + + if (newException != nullptr) + { + throw newException; + } + return result; } }}}} -- cgit v1.2.1