activemq-cpp-3.8.2
CMSExceptionSupport.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _ACTIVEMQ_UTIL_CMSEXCEPTIONSUPPORT_H_
19 #define _ACTIVEMQ_UTIL_CMSEXCEPTIONSUPPORT_H_
20 
21 #include <activemq/util/Config.h>
22 
23 #include <cms/CMSException.h>
37 #include <cms/XAException.h>
38 
39 #include <decaf/lang/Exception.h>
40 
41 #include <string>
42 
43 namespace activemq {
44 namespace util {
45 
47  private:
48 
50 
51  public:
52 
53  virtual ~CMSExceptionSupport();
54 
55  static cms::CMSException create(const std::string& msg, const decaf::lang::Exception& cause);
56 
57  static cms::CMSException create(const decaf::lang::Exception& cause);
58 
59  static cms::MessageEOFException createMessageEOFException(const decaf::lang::Exception& cause);
60 
61  static cms::MessageFormatException createMessageFormatException(const decaf::lang::Exception& cause);
62 
63  };
64 
65 }}
66 
73 #define AMQ_CATCH_ALL_THROW_CMSEXCEPTION() \
74  catch (cms::CMSSecurityException& ex) { \
75  ex.setMark(__FILE__, __LINE__); \
76  throw; \
77  } catch (cms::IllegalStateException& ex) { \
78  ex.setMark(__FILE__, __LINE__); \
79  throw; \
80  } catch (cms::InvalidClientIdException& ex) { \
81  ex.setMark(__FILE__, __LINE__); \
82  throw; \
83  } catch (cms::InvalidDestinationException& ex) { \
84  ex.setMark(__FILE__, __LINE__); \
85  throw; \
86  } catch (cms::InvalidSelectorException& ex) { \
87  ex.setMark(__FILE__, __LINE__); \
88  throw; \
89  } catch (cms::MessageEOFException& ex) { \
90  ex.setMark(__FILE__, __LINE__); \
91  throw; \
92  } catch (cms::MessageFormatException& ex) { \
93  ex.setMark(__FILE__, __LINE__); \
94  throw; \
95  } catch (cms::MessageNotReadableException& ex) { \
96  ex.setMark(__FILE__, __LINE__); \
97  throw; \
98  } catch (cms::MessageNotWriteableException& ex) { \
99  ex.setMark(__FILE__, __LINE__); \
100  throw; \
101  } catch (cms::ResourceAllocationException& ex) { \
102  ex.setMark(__FILE__, __LINE__); \
103  throw; \
104  } catch (cms::TransactionInProgressException& ex) { \
105  ex.setMark(__FILE__, __LINE__); \
106  throw; \
107  } catch (cms::TransactionRolledBackException& ex) { \
108  ex.setMark(__FILE__, __LINE__); \
109  throw; \
110  } catch (cms::UnsupportedOperationException& ex) { \
111  ex.setMark(__FILE__, __LINE__); \
112  throw; \
113  } catch (cms::XAException& ex) { \
114  ex.setMark(__FILE__, __LINE__); \
115  throw; \
116  } catch (cms::CMSException& ex) { \
117  ex.setMark(__FILE__, __LINE__); \
118  throw; \
119  } catch (activemq::exceptions::ActiveMQException& ex) { \
120  if (ex.getCause() != NULL) { \
121  const std::exception* cause = ex.getCause(); \
122  { \
123  const cms::CMSSecurityException* exception = \
124  dynamic_cast<const cms::CMSSecurityException*>(cause); \
125  if (exception != NULL) { \
126  throw cms::CMSSecurityException(*exception); \
127  } \
128  } \
129  { \
130  const cms::IllegalStateException* exception = \
131  dynamic_cast<const cms::IllegalStateException*>(cause); \
132  if (exception != NULL) { \
133  throw cms::IllegalStateException(*exception); \
134  } \
135  } \
136  { \
137  const cms::InvalidClientIdException* exception = \
138  dynamic_cast<const cms::InvalidClientIdException*>(cause); \
139  if (exception != NULL) { \
140  throw cms::InvalidClientIdException(*exception); \
141  } \
142  } \
143  { \
144  const cms::InvalidDestinationException* exception = \
145  dynamic_cast<const cms::InvalidDestinationException*>(cause); \
146  if (exception != NULL) { \
147  throw cms::InvalidDestinationException(*exception); \
148  } \
149  } \
150  { \
151  const cms::InvalidSelectorException* exception = \
152  dynamic_cast<const cms::InvalidSelectorException*>(cause); \
153  if (exception != NULL) { \
154  throw cms::InvalidSelectorException(*exception); \
155  } \
156  } \
157  { \
158  const cms::MessageEOFException* exception = \
159  dynamic_cast<const cms::MessageEOFException*>(cause); \
160  if (exception != NULL) { \
161  throw cms::MessageEOFException(*exception); \
162  } \
163  } \
164  { \
165  const cms::MessageFormatException* exception = \
166  dynamic_cast<const cms::MessageFormatException*>(cause); \
167  if (exception != NULL) { \
168  throw cms::MessageFormatException(*exception); \
169  } \
170  } \
171  { \
172  const cms::MessageNotReadableException* exception = \
173  dynamic_cast<const cms::MessageNotReadableException*>(cause); \
174  if (exception != NULL) { \
175  throw cms::MessageNotReadableException(*exception); \
176  } \
177  } \
178  { \
179  const cms::MessageNotWriteableException* exception = \
180  dynamic_cast<const cms::MessageNotWriteableException*>(cause); \
181  if (exception != NULL) { \
182  throw cms::MessageNotWriteableException(*exception); \
183  } \
184  } \
185  { \
186  const cms::ResourceAllocationException* exception = \
187  dynamic_cast<const cms::ResourceAllocationException*>(cause); \
188  if (exception != NULL) { \
189  throw cms::ResourceAllocationException(*exception); \
190  } \
191  } \
192  { \
193  const cms::TransactionInProgressException* exception = \
194  dynamic_cast<const cms::TransactionInProgressException*>(cause); \
195  if (exception != NULL) { \
196  throw cms::TransactionInProgressException(*exception); \
197  } \
198  } \
199  { \
200  const cms::TransactionRolledBackException* exception = \
201  dynamic_cast<const cms::TransactionRolledBackException*>(cause); \
202  if (exception != NULL) { \
203  throw cms::TransactionRolledBackException(*exception); \
204  } \
205  } \
206  { \
207  const cms::UnsupportedOperationException* exception = \
208  dynamic_cast<const cms::UnsupportedOperationException*>(cause); \
209  if (exception != NULL) { \
210  throw cms::UnsupportedOperationException(*exception); \
211  } \
212  } \
213  { \
214  const cms::XAException* exception = \
215  dynamic_cast<const cms::XAException*>(cause); \
216  if (exception != NULL) { \
217  throw cms::XAException(*exception); \
218  } \
219  } \
220  { \
221  const cms::CMSException* exception = \
222  dynamic_cast<const cms::CMSException*>(cause); \
223  if (exception != NULL) { \
224  throw cms::CMSException(*exception); \
225  } \
226  } \
227  } \
228  ex.setMark(__FILE__, __LINE__); \
229  throw ex.convertToCMSException(); \
230  } catch(decaf::lang::Exception& ex){ \
231  ex.setMark(__FILE__, __LINE__); \
232  activemq::exceptions::ActiveMQException amqEx(ex); \
233  throw amqEx.convertToCMSException(); \
234  } catch(std::exception& ex){ \
235  throw cms::CMSException(ex.what(), NULL); \
236  } catch(...) { \
237  throw cms::CMSException("Caught Unknown Exception", NULL); \
238  }
239 
240 #endif /* _ACTIVEMQ_UTIL_CMSEXCEPTIONSUPPORT_H_ */
#define AMQCPP_API
Definition: Config.h:30
This exception must be thrown when a CMS client attempts to use a data type not supported by a messag...
Definition: MessageFormatException.h:35
CMS API Exception that is the base for all exceptions thrown from CMS classes.
Definition: CMSException.h:50
This exception must be thrown when an unexpected end of stream has been reached when a StreamMessage ...
Definition: MessageEOFException.h:32
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements...
Definition: CachedConsumer.h:24
Definition: Exception.h:38
Definition: CMSExceptionSupport.h:46