BLPAPI C++ 3.26.5
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
35
36#ifndef INCLUDED_BLPAPI_EXCEPTION
37#define INCLUDED_BLPAPI_EXCEPTION
38
110
111#ifndef INCLUDED_BLPAPI_DEFS
112#include <blpapi_defs.h>
113#endif
114
115#ifndef INCLUDED_BLPAPI_ERROR
116#include <blpapi_error.h>
117#endif
118
119#ifdef __cplusplus
120extern "C" {
121#endif
122
124
135struct blpapi_ErrorInfo {
136 int exceptionClass;
137 char description[256];
138};
139
140typedef struct blpapi_ErrorInfo blpapi_ErrorInfo_t;
141
142BLPAPI_EXPORT
143int blpapi_getErrorInfo(blpapi_ErrorInfo_t *buffer, int errorCode);
144
148
149#ifdef __cplusplus
150} // extern "C"
151
152#ifndef INCLUDED_EXCEPTION
153#include <exception>
154#define INCLUDED_EXCEPTION
155#endif
156
157#ifndef INCLUDED_STRING
158#include <string>
159#define INCLUDED_STRING
160#endif
161
168
169namespace BloombergLP {
170namespace blpapi {
171
179class Exception : public std::exception {
180
181 const std::string d_description;
182
183 private:
184 // NOT IMPLEMENTED
185 Exception& operator=(const Exception&); // = delete
186
187 public:
188 // CREATORS
189 explicit Exception(const std::string& description);
194
195 // ACCESSORS
196 const std::string& description() const throw();
200
201 virtual const char *what() const throw();
206
207 virtual ~Exception() throw();
211};
212
221 public:
222 // CREATORS
223 explicit DuplicateCorrelationIdException(const std::string& description);
228};
229
238 public:
239 // CREATORS
240 explicit InvalidStateException(const std::string& description);
245};
246
254 public:
255 // CREATORS
256 explicit InvalidArgumentException(const std::string& description);
261};
262
270 public:
271 // CREATORS
272 explicit InvalidConversionException(const std::string& description);
277};
278
287 public:
288 // CREATORS
289 explicit IndexOutOfRangeException(const std::string& description);
294};
295
306 public:
307 // CREATORS
308 explicit FieldNotFoundException(const std::string& description);
313};
314
323 public:
324 // CREATORS
325 explicit UnknownErrorException(const std::string& description);
330};
331
339 public:
340 // CREATORS
341 explicit UnsupportedOperationException(const std::string& description);
346};
347
356 public:
357 // CREATORS
358 explicit NotFoundException(const std::string& description);
363};
364
373
374 private:
375 static void throwException(int errorCode);
380
381 public:
382 static void throwOnError(int errorCode);
387};
388
391
392// ============================================================================
393// INLINE FUNCTION DEFINITIONS
394// ============================================================================
395
396// ---------------
397// class Exception
398// ---------------
399
400inline Exception::Exception(const std::string& newDescription)
401 : d_description(newDescription)
402{
403}
404
405inline Exception::~Exception() throw() { }
406
407inline const std::string& Exception::description() const throw()
408{
409 return d_description;
410}
411
412inline const char *Exception::what() const throw()
413{
414 return description().c_str();
415}
416
417// -------------------------------------
418// class DuplicateCorrelationIdException
419// -------------------------------------
420
422 const std::string& newDescription)
423 : Exception(newDescription)
424{
425}
426
427// ---------------------------
428// class InvalidStateException
429// ---------------------------
430
432 const std::string& newDescription)
433 : Exception(newDescription)
434{
435}
436
437// ------------------------------
438// class InvalidArgumentException
439// ------------------------------
440
442 const std::string& newDescription)
443 : Exception(newDescription)
444{
445}
446
447// --------------------------------
448// class InvalidConversionException
449// --------------------------------
450
452 const std::string& newDescription)
453 : Exception(newDescription)
454{
455}
456
457// ------------------------------
458// class IndexOutOfRangeException
459// ------------------------------
460
462 const std::string& newDescription)
463 : Exception(newDescription)
464{
465}
466
467// ----------------------------
468// class FieldNotFoundException
469// ----------------------------
470
472 const std::string& newDescription)
473 : Exception(newDescription)
474{
475}
476
477// ---------------------------
478// class UnknownErrorException
479// ---------------------------
480
482 const std::string& newDescription)
483 : Exception(newDescription)
484{
485}
486
487// -----------------------------------
488// class UnsupportedOperationException
489// -----------------------------------
490
492 const std::string& newDescription)
493 : Exception(newDescription)
494{
495}
496
497// -----------------------
498// class NotFoundException
499// -----------------------
500
501inline NotFoundException::NotFoundException(const std::string& newDescription)
502 : Exception(newDescription)
503{
504}
505
506// -------------------
507// class ExceptionUtil
508// -------------------
509
510inline void ExceptionUtil::throwException(int errorCode)
511{
512 const char *description = blpapi_getLastErrorDescription(errorCode);
513 if (!description) {
514 description = "Unknown";
515 }
516
517 if (BLPAPI_ERROR_DUPLICATE_CORRELATIONID == errorCode) {
518 throw DuplicateCorrelationIdException(description);
519 }
520
521 switch (BLPAPI_RESULTCLASS(errorCode))
522 case BLPAPI_INVALIDSTATE_CLASS: {
523 throw InvalidStateException(description);
524 case BLPAPI_INVALIDARG_CLASS:
525 throw InvalidArgumentException(description);
526 case BLPAPI_CNVERROR_CLASS:
527 throw InvalidConversionException(description);
528 case BLPAPI_BOUNDSERROR_CLASS:
529 throw IndexOutOfRangeException(description);
530 case BLPAPI_FLDNOTFOUND_CLASS:
531 throw FieldNotFoundException(description);
532 case BLPAPI_UNSUPPORTED_CLASS:
533 throw UnsupportedOperationException(description);
534 case BLPAPI_NOTFOUND_CLASS:
535 throw NotFoundException(description);
536 default:
537 throw Exception(description);
538 }
539}
540
541inline void ExceptionUtil::throwOnError(int errorCode)
542{
543 if (errorCode) {
544 throwException(errorCode);
545 }
546}
547
548} // close namespace blpapi {
549} // close namespace BloombergLP {
550
551#endif
552
553#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:421
Definition blpapi_exception.h:372
static void throwOnError(int errorCode)
Definition blpapi_exception.h:541
Exception(const std::string &description)
Definition blpapi_exception.h:400
virtual const char * what() const
Definition blpapi_exception.h:412
const std::string & description() const
Definition blpapi_exception.h:407
virtual ~Exception()
Definition blpapi_exception.h:405
FieldNotFoundException(const std::string &description)
Definition blpapi_exception.h:471
IndexOutOfRangeException(const std::string &description)
Definition blpapi_exception.h:461
InvalidArgumentException(const std::string &description)
Definition blpapi_exception.h:441
InvalidConversionException(const std::string &description)
Definition blpapi_exception.h:451
InvalidStateException(const std::string &description)
Definition blpapi_exception.h:431
NotFoundException(const std::string &description)
Definition blpapi_exception.h:501
UnknownErrorException(const std::string &description)
Definition blpapi_exception.h:481
UnsupportedOperationException(const std::string &description)
Definition blpapi_exception.h:491
Definition blpapi_abstractsession.h:211