BLPAPI C++ 3.26.6
Loading...
Searching...
No Matches
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
37
38#ifndef INCLUDED_BLPAPI_EXCEPTION
39#define INCLUDED_BLPAPI_EXCEPTION
40
111
112#include <blpapi_defs.h>
113#include <blpapi_error.h>
114
115#ifdef __cplusplus
116extern "C" {
117#endif
118
120
131struct blpapi_ErrorInfo {
132 int exceptionClass;
133 char description[256];
134};
135
136typedef struct blpapi_ErrorInfo blpapi_ErrorInfo_t;
137
165BLPAPI_EXPORT
166int blpapi_getErrorInfo(blpapi_ErrorInfo_t *buffer, int errorCode);
167
171
172#ifdef __cplusplus
173} // extern "C"
174
175#include <exception>
176#include <string>
177
178namespace BloombergLP {
179namespace blpapi {
186
194class Exception : public std::exception {
195
196 const std::string d_description;
197
198 private:
199 // NOT IMPLEMENTED
200 Exception& operator=(const Exception&); // = delete
201
202 public:
203 // CREATORS
204 explicit Exception(const std::string& description);
209
210 // ACCESSORS
211 const std::string& description() const throw();
215
216 virtual const char *what() const throw();
221
222 virtual ~Exception() throw();
226};
227
236 public:
237 // CREATORS
238 explicit DuplicateCorrelationIdException(const std::string& description);
243};
244
253 public:
254 // CREATORS
255 explicit InvalidStateException(const std::string& description);
260};
261
269 public:
270 // CREATORS
271 explicit InvalidArgumentException(const std::string& description);
276};
277
285 public:
286 // CREATORS
287 explicit InvalidConversionException(const std::string& description);
292};
293
302 public:
303 // CREATORS
304 explicit IndexOutOfRangeException(const std::string& description);
309};
310
321 public:
322 // CREATORS
323 explicit FieldNotFoundException(const std::string& description);
328};
329
338 public:
339 // CREATORS
340 explicit UnknownErrorException(const std::string& description);
345};
346
354 public:
355 // CREATORS
356 explicit UnsupportedOperationException(const std::string& description);
361};
362
371 public:
372 // CREATORS
373 explicit NotFoundException(const std::string& description);
378};
379
388
389 private:
390 static void throwException(int errorCode);
395
396 public:
397 static void throwOnError(int errorCode);
402};
403
406
407// ============================================================================
408// INLINE FUNCTION DEFINITIONS
409// ============================================================================
410
411// ---------------
412// class Exception
413// ---------------
414
415inline Exception::Exception(const std::string& newDescription)
416 : d_description(newDescription)
417{
418}
419
420inline Exception::~Exception() throw() { }
421
422inline const std::string& Exception::description() const throw()
423{
424 return d_description;
425}
426
427inline const char *Exception::what() const throw()
428{
429 return description().c_str();
430}
431
432// -------------------------------------
433// class DuplicateCorrelationIdException
434// -------------------------------------
435
437 const std::string& newDescription)
438 : Exception(newDescription)
439{
440}
441
442// ---------------------------
443// class InvalidStateException
444// ---------------------------
445
447 const std::string& newDescription)
448 : Exception(newDescription)
449{
450}
451
452// ------------------------------
453// class InvalidArgumentException
454// ------------------------------
455
457 const std::string& newDescription)
458 : Exception(newDescription)
459{
460}
461
462// --------------------------------
463// class InvalidConversionException
464// --------------------------------
465
467 const std::string& newDescription)
468 : Exception(newDescription)
469{
470}
471
472// ------------------------------
473// class IndexOutOfRangeException
474// ------------------------------
475
477 const std::string& newDescription)
478 : Exception(newDescription)
479{
480}
481
482// ----------------------------
483// class FieldNotFoundException
484// ----------------------------
485
487 const std::string& newDescription)
488 : Exception(newDescription)
489{
490}
491
492// ---------------------------
493// class UnknownErrorException
494// ---------------------------
495
497 const std::string& newDescription)
498 : Exception(newDescription)
499{
500}
501
502// -----------------------------------
503// class UnsupportedOperationException
504// -----------------------------------
505
507 const std::string& newDescription)
508 : Exception(newDescription)
509{
510}
511
512// -----------------------
513// class NotFoundException
514// -----------------------
515
516inline NotFoundException::NotFoundException(const std::string& newDescription)
517 : Exception(newDescription)
518{
519}
520
521// -------------------
522// class ExceptionUtil
523// -------------------
524
525inline void ExceptionUtil::throwException(int errorCode)
526{
527 const char *description = blpapi_getLastErrorDescription(errorCode);
528 if (!description) {
529 description = "Unknown";
530 }
531
532 if (BLPAPI_ERROR_DUPLICATE_CORRELATIONID == errorCode) {
533 throw DuplicateCorrelationIdException(description);
534 }
535
536 switch (BLPAPI_RESULTCLASS(errorCode))
537 case BLPAPI_INVALIDSTATE_CLASS: {
538 throw InvalidStateException(description);
539 case BLPAPI_INVALIDARG_CLASS:
540 throw InvalidArgumentException(description);
541 case BLPAPI_CNVERROR_CLASS:
542 throw InvalidConversionException(description);
543 case BLPAPI_BOUNDSERROR_CLASS:
544 throw IndexOutOfRangeException(description);
545 case BLPAPI_FLDNOTFOUND_CLASS:
546 throw FieldNotFoundException(description);
547 case BLPAPI_UNSUPPORTED_CLASS:
548 throw UnsupportedOperationException(description);
549 case BLPAPI_NOTFOUND_CLASS:
550 throw NotFoundException(description);
551 default:
552 throw Exception(description);
553 }
554}
555
556inline void ExceptionUtil::throwOnError(int errorCode)
557{
558 if (errorCode) {
559 throwException(errorCode);
560 }
561}
562
563} // close namespace blpapi {
564} // close namespace BloombergLP {
565
566#endif
567
568#endif // #ifndef INCLUDED_BLPAPI_EXCEPTION
Common definitions used by the library.
Provide a collection of errors that library can return.
DuplicateCorrelationIdException(const std::string &description)
Definition blpapi_exception.h:436
Definition blpapi_exception.h:387
static void throwOnError(int errorCode)
Definition blpapi_exception.h:556
Exception(const std::string &description)
Definition blpapi_exception.h:415
virtual const char * what() const
Definition blpapi_exception.h:427
const std::string & description() const
Definition blpapi_exception.h:422
virtual ~Exception()
Definition blpapi_exception.h:420
FieldNotFoundException(const std::string &description)
Definition blpapi_exception.h:486
IndexOutOfRangeException(const std::string &description)
Definition blpapi_exception.h:476
InvalidArgumentException(const std::string &description)
Definition blpapi_exception.h:456
InvalidConversionException(const std::string &description)
Definition blpapi_exception.h:466
InvalidStateException(const std::string &description)
Definition blpapi_exception.h:446
NotFoundException(const std::string &description)
Definition blpapi_exception.h:516
UnknownErrorException(const std::string &description)
Definition blpapi_exception.h:496
UnsupportedOperationException(const std::string &description)
Definition blpapi_exception.h:506
Definition blpapi_abstractsession.h:452
Definition blpapi_abstractsession.h:451