summaryrefslogtreecommitdiff
path: root/cpp/bindings/qpid/dotnet/src/Connection.cpp
diff options
context:
space:
mode:
authorCharles E. Rolke <chug@apache.org>2010-11-02 20:50:54 +0000
committerCharles E. Rolke <chug@apache.org>2010-11-02 20:50:54 +0000
commit958647601758a9cbd78082a76c3583c3ce9e852e (patch)
tree6cdf429527ceca889f12ffbfa79b5f52efe69b9c /cpp/bindings/qpid/dotnet/src/Connection.cpp
parenta3185a06c97c8775b58e6b5207674f0c1c51e287 (diff)
downloadqpid-python-958647601758a9cbd78082a76c3583c3ce9e852e.tar.gz
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
Diffstat (limited to 'cpp/bindings/qpid/dotnet/src/Connection.cpp')
-rw-r--r--cpp/bindings/qpid/dotnet/src/Connection.cpp142
1 files changed, 124 insertions, 18 deletions
diff --git a/cpp/bindings/qpid/dotnet/src/Connection.cpp b/cpp/bindings/qpid/dotnet/src/Connection.cpp
index 322910d820..d0c5bc9ac5 100644
--- a/cpp/bindings/qpid/dotnet/src/Connection.cpp
+++ b/cpp/bindings/qpid/dotnet/src/Connection.cpp
@@ -43,36 +43,97 @@ namespace Messaging {
/// </summary>
// constructors
- Connection::Connection(System::String ^ url) :
- connectionp(new ::qpid::messaging::Connection(QpidMarshal::ToNative(url)))
+ Connection::Connection(System::String ^ url)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ connectionp = new ::qpid::messaging::Connection(QpidMarshal::ToNative(url));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
Connection::Connection(System::String ^ url,
System::Collections::Generic::Dictionary<
- System::String ^, System::Object ^> ^ options) :
- connectionp(new ::qpid::messaging::Connection(QpidMarshal::ToNative(url)))
+ System::String ^, System::Object ^> ^ options)
{
- for each (System::Collections::Generic::KeyValuePair<System::String^, System::Object^> kvp in options)
- {
- SetOption(kvp.Key, kvp.Value);
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ connectionp = new ::qpid::messaging::Connection(QpidMarshal::ToNative(url));
+
+ for each (System::Collections::Generic::KeyValuePair<System::String^, System::Object^> kvp in options)
+ {
+ SetOption(kvp.Key, kvp.Value);
+ }
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
}
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
- Connection::Connection(System::String ^ url, System::String ^ options) :
- connectionp(new ::qpid::messaging::Connection(QpidMarshal::ToNative(url),
- QpidMarshal::ToNative(options)))
+ Connection::Connection(System::String ^ url, System::String ^ options)
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ connectionp = new ::qpid::messaging::Connection(QpidMarshal::ToNative(url),
+ QpidMarshal::ToNative(options));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
// Copy constructor
Connection::Connection(const Connection ^ connection)
- : connectionp(new ::qpid::messaging::Connection(
- *(const_cast<Connection ^>(connection)->NativeConnection)))
{
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ connectionp = new ::qpid::messaging::Connection(
+ *(const_cast<Connection ^>(connection)->NativeConnection));
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
@@ -104,20 +165,65 @@ namespace Messaging {
void Connection::SetOption(System::String ^ name, System::Object ^ value)
{
- ::qpid::types::Variant entryValue;
- TypeTranslator::ManagedToNativeObject(value, entryValue);
- std::string entryName = QpidMarshal::ToNative(name);
- connectionp->::qpid::messaging::Connection::setOption(entryName, entryValue);
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ ::qpid::types::Variant entryValue;
+ TypeTranslator::ManagedToNativeObject(value, entryValue);
+ std::string entryName = QpidMarshal::ToNative(name);
+ connectionp->::qpid::messaging::Connection::setOption(entryName, entryValue);
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Connection::Open()
{
- connectionp->open();
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ connectionp->open();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
void Connection::Close()
{
- connectionp->close();
+ System::Exception ^ newException = nullptr;
+
+ try
+ {
+ connectionp->close();
+ }
+ catch (const ::qpid::types::Exception & error)
+ {
+ String ^ errmsg = gcnew String(error.what());
+ newException = gcnew QpidException(errmsg);
+ }
+
+ if (newException != nullptr)
+ {
+ throw newException;
+ }
}
//