BLPAPI C++  3.23.2
blpapi_exception.h
Go to the documentation of this file.
1 /* Copyright 2012. Bloomberg Finance L.P.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions: The above
9  * copyright notice and this permission notice shall be included in all copies
10  * or substantial portions of the Software.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18  * IN THE SOFTWARE.
19  */
20 
28 #ifndef INCLUDED_BLPAPI_EXCEPTION
29 #define INCLUDED_BLPAPI_EXCEPTION
30 
103 #ifndef INCLUDED_BLPAPI_DEFS
104 #include <blpapi_defs.h>
105 #endif
106 
107 #ifndef INCLUDED_BLPAPI_ERROR
108 #include <blpapi_error.h>
109 #endif
110 
111 #ifdef __cplusplus
112 extern "C" {
113 #endif
114 
123  char description[256];
124 };
125 
127 
129 int blpapi_getErrorInfo(blpapi_ErrorInfo_t *buffer, int errorCode);
130 
131 #ifdef __cplusplus
132 } // extern "C"
133 
137 #ifndef INCLUDED_EXCEPTION
138 #include <exception>
139 #define INCLUDED_EXCEPTION
140 #endif
141 
142 #ifndef INCLUDED_STRING
143 #include <string>
144 #define INCLUDED_STRING
145 #endif
146 
154 namespace BloombergLP {
155 namespace blpapi {
156 
164 class Exception : public std::exception {
165 
166  const std::string d_description;
167 
168  private:
169  // NOT IMPLEMENTED
170  Exception& operator=(const Exception&); // = delete
171 
172  public:
173  // CREATORS
174  explicit Exception(const std::string& description);
180  // ACCESSORS
181  const std::string& description() const throw();
186  virtual const char *what() const throw();
192  virtual ~Exception() throw();
196 };
197 
206  public:
207  // CREATORS
208  explicit DuplicateCorrelationIdException(const std::string& description);
213 };
214 
223  public:
224  // CREATORS
225  explicit InvalidStateException(const std::string& description);
230 };
231 
239  public:
240  // CREATORS
241  explicit InvalidArgumentException(const std::string& description);
246 };
247 
255  public:
256  // CREATORS
257  explicit InvalidConversionException(const std::string& description);
262 };
263 
272  public:
273  // CREATORS
274  explicit IndexOutOfRangeException(const std::string& description);
279 };
280 
291  public:
292  // CREATORS
293  explicit FieldNotFoundException(const std::string& description);
298 };
299 
308  public:
309  // CREATORS
310  explicit UnknownErrorException(const std::string& description);
315 };
316 
324  public:
325  // CREATORS
326  explicit UnsupportedOperationException(const std::string& description);
331 };
332 
340 class NotFoundException : public Exception {
341  public:
342  // CREATORS
343  explicit NotFoundException(const std::string& description);
348 };
349 
358 
359  private:
360  static void throwException(int errorCode);
366  public:
367  static void throwOnError(int errorCode);
372 };
373 
377 // ============================================================================
378 // INLINE FUNCTION DEFINITIONS
379 // ============================================================================
380 
381 // ---------------
382 // class Exception
383 // ---------------
384 
385 inline Exception::Exception(const std::string& newDescription)
386  : d_description(newDescription)
387 {
388 }
389 
390 inline Exception::~Exception() throw() { }
391 
392 inline const std::string& Exception::description() const throw()
393 {
394  return d_description;
395 }
396 
397 inline const char *Exception::what() const throw()
398 {
399  return description().c_str();
400 }
401 
402 // -------------------------------------
403 // class DuplicateCorrelationIdException
404 // -------------------------------------
405 
407  const std::string& newDescription)
408  : Exception(newDescription)
409 {
410 }
411 
412 // ---------------------------
413 // class InvalidStateException
414 // ---------------------------
415 
417  const std::string& newDescription)
418  : Exception(newDescription)
419 {
420 }
421 
422 // ------------------------------
423 // class InvalidArgumentException
424 // ------------------------------
425 
427  const std::string& newDescription)
428  : Exception(newDescription)
429 {
430 }
431 
432 // --------------------------------
433 // class InvalidConversionException
434 // --------------------------------
435 
437  const std::string& newDescription)
438  : Exception(newDescription)
439 {
440 }
441 
442 // ------------------------------
443 // class IndexOutOfRangeException
444 // ------------------------------
445 
447  const std::string& newDescription)
448  : Exception(newDescription)
449 {
450 }
451 
452 // ----------------------------
453 // class FieldNotFoundException
454 // ----------------------------
455 
457  const std::string& newDescription)
458  : Exception(newDescription)
459 {
460 }
461 
462 // ---------------------------
463 // class UnknownErrorException
464 // ---------------------------
465 
467  const std::string& newDescription)
468  : Exception(newDescription)
469 {
470 }
471 
472 // -----------------------------------
473 // class UnsupportedOperationException
474 // -----------------------------------
475 
477  const std::string& newDescription)
478  : Exception(newDescription)
479 {
480 }
481 
482 // -----------------------
483 // class NotFoundException
484 // -----------------------
485 
486 inline NotFoundException::NotFoundException(const std::string& newDescription)
487  : Exception(newDescription)
488 {
489 }
490 
491 // -------------------
492 // class ExceptionUtil
493 // -------------------
494 
495 inline void ExceptionUtil::throwException(int errorCode)
496 {
497  const char *description = blpapi_getLastErrorDescription(errorCode);
498  if (!description) {
499  description = "Unknown";
500  }
501 
502  if (BLPAPI_ERROR_DUPLICATE_CORRELATIONID == errorCode) {
503  throw DuplicateCorrelationIdException(description);
504  }
505 
506  switch (BLPAPI_RESULTCLASS(errorCode))
508  throw InvalidStateException(description);
510  throw InvalidArgumentException(description);
512  throw InvalidConversionException(description);
514  throw IndexOutOfRangeException(description);
516  throw FieldNotFoundException(description);
518  throw UnsupportedOperationException(description);
520  throw NotFoundException(description);
521  default:
522  throw Exception(description);
523  }
524 }
525 
526 inline void ExceptionUtil::throwOnError(int errorCode)
527 {
528  if (errorCode) {
529  throwException(errorCode);
530  }
531 }
532 
533 } // close namespace blpapi {
534 } // close namespace BloombergLP {
535 
536 #endif
537 
538 #endif // #ifndef INCLUDED_BLPAPI_EXCEPTION
Definition: blpapi_exception.h:121
#define BLPAPI_FLDNOTFOUND_CLASS
Definition: blpapi_error.h:63
int exceptionClass
Definition: blpapi_exception.h:122
InvalidConversionException(const std::string &description)
Definition: blpapi_exception.h:436
Common definitions used by the library.
Definition: blpapi_exception.h:290
Definition: blpapi_exception.h:271
#define BLPAPI_ERROR_DUPLICATE_CORRELATIONID
Definition: blpapi_error.h:70
Definition: blpapi_abstractsession.h:220
Definition: blpapi_exception.h:323
Exception(const std::string &description)
Definition: blpapi_exception.h:385
Definition: blpapi_exception.h:222
virtual const char * what() const
Definition: blpapi_exception.h:397
#define BLPAPI_BOUNDSERROR_CLASS
Definition: blpapi_error.h:61
const std::string & description() const
Definition: blpapi_exception.h:392
int blpapi_getErrorInfo(blpapi_ErrorInfo_t *buffer, int errorCode)
static void throwOnError(int errorCode)
Definition: blpapi_exception.h:526
#define BLPAPI_INVALIDSTATE_CLASS
Definition: blpapi_error.h:57
FieldNotFoundException(const std::string &description)
Definition: blpapi_exception.h:456
Definition: blpapi_exception.h:254
#define BLPAPI_RESULTCLASS(res)
Definition: blpapi_error.h:54
Definition: blpapi_exception.h:357
InvalidArgumentException(const std::string &description)
Definition: blpapi_exception.h:426
#define BLPAPI_NOTFOUND_CLASS
Definition: blpapi_error.h:62
Definition: blpapi_exception.h:340
char description[256]
Definition: blpapi_exception.h:123
const char * blpapi_getLastErrorDescription(int resultCode)
UnknownErrorException(const std::string &description)
Definition: blpapi_exception.h:466
InvalidStateException(const std::string &description)
Definition: blpapi_exception.h:416
IndexOutOfRangeException(const std::string &description)
Definition: blpapi_exception.h:446
Definition: blpapi_exception.h:164
UnsupportedOperationException(const std::string &description)
Definition: blpapi_exception.h:476
Definition: blpapi_exception.h:307
#define BLPAPI_EXPORT
Definition: blpapi_defs.h:171
DuplicateCorrelationIdException(const std::string &description)
Definition: blpapi_exception.h:406
#define BLPAPI_UNSUPPORTED_CLASS
Definition: blpapi_error.h:64
#define BLPAPI_CNVERROR_CLASS
Definition: blpapi_error.h:60
Provide a collection of errors that library can return.
Definition: blpapi_exception.h:238
#define BLPAPI_INVALIDARG_CLASS
Definition: blpapi_error.h:58
NotFoundException(const std::string &description)
Definition: blpapi_exception.h:486
virtual ~Exception()
Definition: blpapi_exception.h:390