Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / tao / Messaging / ExceptionHolder_i.cpp
blob4fb71b15a0d3bf3aea17fa5ab98cbbe767582f54
1 // -*- C++ -*-
2 #include "tao/Messaging/ExceptionHolder_i.h"
4 #include "tao/Messaging/Messaging.h"
5 #include "tao/Exception_Data.h"
6 #include "tao/CDR.h"
8 #include <memory>
10 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
12 namespace TAO
14 ExceptionHolder::ExceptionHolder () :
15 data_ (0),
16 count_ (0),
17 char_translator_ (0),
18 wchar_translator_ (0)
22 ExceptionHolder::ExceptionHolder (
23 ::CORBA::Boolean is_system_exception,
24 ::CORBA::Boolean byte_order,
25 const ::CORBA::OctetSeq &marshaled_exception,
26 ::TAO::Exception_Data* data,
27 ::CORBA::ULong exceptions_count,
28 ACE_Char_Codeset_Translator *char_translator,
29 ACE_WChar_Codeset_Translator *wchar_translator) :
30 ::OBV_Messaging::ExceptionHolder (is_system_exception, byte_order, marshaled_exception),
31 data_ (data),
32 count_ (exceptions_count),
33 char_translator_ (char_translator),
34 wchar_translator_ (wchar_translator)
38 ExceptionHolder::~ExceptionHolder ()
42 void
43 ExceptionHolder::set_exception_data (::TAO::Exception_Data* data,
44 ::CORBA::ULong exceptions_count)
46 this->data_ = data;
47 this->count_ = exceptions_count;
50 void ExceptionHolder::raise_exception ()
52 TAO_InputCDR _tao_in ((const char*) this->marshaled_exception ().get_buffer (),
53 this->marshaled_exception ().length (),
54 this->byte_order ());
56 _tao_in.char_translator (this->char_translator_);
57 _tao_in.wchar_translator (this->wchar_translator_);
59 CORBA::String_var type_id;
61 if (!(_tao_in >> type_id.inout ()))
63 // Could not demarshal the exception id, raise a local
64 // CORBA::MARSHAL
65 throw ::CORBA::MARSHAL (TAO::VMCID, CORBA::COMPLETED_YES);
68 if (this->is_system_exception ())
70 CORBA::ULong minor = 0;
71 CORBA::ULong completion = 0;
72 if (!(_tao_in >> minor) ||
73 !(_tao_in >> completion))
75 throw ::CORBA::MARSHAL (TAO::VMCID, CORBA::COMPLETED_MAYBE);
78 CORBA::SystemException* exception =
79 TAO::create_system_exception (type_id.in ());
81 if (!exception)
83 // @@ We should raise a CORBA::NO_MEMORY, but we ran out
84 // of memory already. We need a pre-allocated, TSS,
85 // CORBA::NO_MEMORY instance
86 ACE_NEW (exception, CORBA::UNKNOWN);
88 exception->minor (minor);
89 exception->completed (CORBA::CompletionStatus (completion));
91 // Raise the exception.
92 std::unique_ptr<CORBA::SystemException> e_ptr(exception);
93 exception->_raise ();
95 return;
98 // Match the exception interface repository id with the
99 // exception in the exception list.
100 // This is important to decode the exception.
101 for (CORBA::ULong i = 0; i != this->count_; ++i)
103 if (ACE_OS::strcmp (type_id.in (), this->data_[i].id) != 0)
104 continue;
106 CORBA::Exception * const exception = this->data_[i].alloc ();
108 if (exception == 0)
110 throw ::CORBA::NO_MEMORY (TAO::VMCID, CORBA::COMPLETED_YES);
112 else
114 exception->_tao_decode (_tao_in);
117 // Raise the exception.
118 std::unique_ptr<CORBA::Exception> e_ptr (exception);
119 exception->_raise ();
121 return;
124 // If we couldn't find the right exception, report it as
125 // CORBA::UNKNOWN.
127 // @@ It would seem like if the remote exception is a
128 // UserException we can assume that the request was
129 // completed.
130 throw ::CORBA::UNKNOWN (TAO::VMCID, CORBA::COMPLETED_YES);
133 void ExceptionHolder::raise_exception_with_list (
134 const ::Dynamic::ExceptionList &)
136 // todo convert exceptionlist to something we can really use.
137 this->raise_exception ();
140 CORBA::ValueBase*
141 ExceptionHolder::_copy_value ()
143 TAO::ExceptionHolder* ret_val = 0;
144 ACE_NEW_THROW_EX (ret_val,
145 ExceptionHolder,
146 CORBA::NO_MEMORY ());
148 // @todo According to the latest corba spec we should be able to
149 // pass this to the ExceptionHolder constructor but the TAO_IDL
150 // compiler doesn't seem to generate this.
151 ret_val->is_system_exception (this->is_system_exception ());
152 ret_val->byte_order (this->byte_order ());
153 ret_val->marshaled_exception (this->marshaled_exception ());
155 return ret_val;
158 CORBA::ValueBase *
159 ExceptionHolderFactory::create_for_unmarshal ()
161 TAO::ExceptionHolder* ret_val = 0;
162 ACE_NEW_THROW_EX (ret_val,
163 ExceptionHolder,
164 CORBA::NO_MEMORY ());
165 return ret_val;
169 TAO_END_VERSIONED_NAMESPACE_DECL