48 #ifndef __ERROR_HANDLING__
49 #define __ERROR_HANDLING__
51 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
55 #include "daal_string.h"
56 #include "error_indexes.h"
58 #include "services/collection.h"
70 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
76 struct DAAL_EXPORT Exception : std::exception
83 Exception(
const char *description) : _description(description) {};
89 virtual const char *what()
const throw() {
return _description.c_str(); };
95 virtual ~Exception() throw() {}
102 static Exception getException(
const String &description)
104 String d(description);
105 return Exception(d.c_str());
112 static Exception getException(
const char *description)
114 return Exception(description);
124 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
125 using interface1::Exception;
135 class DAAL_EXPORT Error
144 Error(
const ErrorID
id = NoErrorMessageFound);
150 Error(
const Error &e);
159 ErrorID id()
const {
return _id; }
165 void setId(ErrorID
id)
174 const char *description()
const;
182 Error &addIntDetail(ErrorDetailID
id,
int value);
190 Error &addDoubleDetail(ErrorDetailID
id,
double value);
198 Error &addStringDetail(ErrorDetailID
id,
const String &value);
204 const ErrorDetail *details()
const {
return _details; }
210 static SharedPtr<Error> create(ErrorID
id);
212 static SharedPtr<Error> create(ErrorID
id, ErrorDetailID det,
int value);
214 static SharedPtr<Error> create(ErrorID
id, ErrorDetailID det,
const String &value);
223 Error &addDetail(ErrorDetail *detail);
227 ErrorDetail *_details;
229 typedef SharedPtr<Error> ErrorPtr;
235 class DAAL_EXPORT KernelErrorCollection :
private Collection<SharedPtr<Error> >
240 typedef Collection<SharedPtr<Error> > super;
245 KernelErrorCollection() : _description(0) {}
251 KernelErrorCollection(
const KernelErrorCollection &other);
258 Error &add(
const ErrorID &
id);
264 void add(
const ErrorPtr &e);
270 void add(
const services::SharedPtr<KernelErrorCollection> &e);
276 void add(
const KernelErrorCollection &e);
282 bool isEmpty()
const {
return size() == 0; }
295 Error *at(
size_t index);
302 const Error *at(
size_t index)
const;
309 Error *operator[](
size_t index);
316 const Error *operator[](
size_t index)
const;
321 virtual ~KernelErrorCollection();
327 const char *getDescription()
const;
330 mutable char *_description;
332 typedef SharedPtr<KernelErrorCollection> KernelErrorCollectionPtr;
338 class DAAL_EXPORT ErrorCollection
346 ErrorCollection() : _errors(new KernelErrorCollection()), _canThrow(true){}
352 ErrorCollection(
const ErrorCollection &o) : _errors(o.getErrors()), _canThrow(o._canThrow) {}
359 explicit ErrorCollection(
const KernelErrorCollection &errors) : _errors(new KernelErrorCollection(errors)), _canThrow(true) {}
365 void add(
const ErrorID &
id)
368 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
370 throw Exception::getException(getDescription());
378 void add(
const ErrorPtr &e)
381 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
383 throw Exception::getException(getDescription());
391 void add(
const ErrorCollection &e)
395 _errors->add(e.getErrors());
396 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
398 throw Exception::getException(getDescription());
408 void add(
const KernelErrorCollectionPtr &e)
413 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
415 throw Exception::getException(getDescription());
426 return _errors->size();
435 return _errors->isEmpty();
441 virtual ~ErrorCollection() {}
447 const KernelErrorCollectionPtr &getErrors()
const
456 const char *getDescription()
const {
return _errors->getDescription(); }
462 bool canThrow()
const
472 bool setCanThrow(
bool bOn)
474 bool bVal = _canThrow;
480 KernelErrorCollectionPtr _errors;
483 typedef SharedPtr<ErrorCollection> ErrorCollectionPtr;
491 class DAAL_EXPORT Status
497 Status() : _impl(0){}
507 Status(
const ErrorPtr& e);
512 Status(
const Status& other);
523 bool ok()
const {
return !_impl; }
529 operator bool()
const {
return ok(); }
536 Status& add(ErrorID
id);
543 Status& add(
const ErrorPtr& e);
550 Status& add(
const Status& other);
557 Status& operator |=(
const Status& other) {
return add(other); }
564 Status& operator =(
const Status& other);
570 const char* getDescription()
const;
581 DAAL_DEPRECATED Status(
const KernelErrorCollection& e);
585 DAAL_DEPRECATED Status(
const ErrorCollection& e);
590 ErrorCollectionPtr getCollection()
const;
596 inline const Status& throwIfPossible(
const Status& s)
598 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
600 throw services::Exception::getException(s.getDescription());
606 using interface1::Error;
607 using interface1::KernelErrorCollection;
608 using interface1::ErrorCollection;
609 using interface1::ErrorPtr;
610 using interface1::KernelErrorCollectionPtr;
611 using interface1::ErrorCollectionPtr;
612 using interface1::Status;
613 using interface1::throwIfPossible;
daal::services::interface1::ErrorDetail
Base for error detail classes.
Definition: error_id.h:70
daal::services::interface1::ErrorCollection::add
void add(const ErrorPtr &e)
Definition: error_handling.h:378
daal::services::NoErrorMessageFound
Definition: error_indexes.h:420
daal::services::interface1::Status
Class that holds the results of API calls. In case of API routine failure it contains the list of err...
Definition: error_handling.h:491
daal
Definition: algorithm_base_common.h:57
daal::services::interface1::Exception::~Exception
virtual ~Exception()
Definition: error_handling.h:95
daal::services::interface1::ErrorCollection::getErrors
const KernelErrorCollectionPtr & getErrors() const
Definition: error_handling.h:447
daal::services::interface1::Status::ok
bool ok() const
Definition: error_handling.h:523
daal::services::interface1::ErrorCollection::~ErrorCollection
virtual ~ErrorCollection()
Definition: error_handling.h:441
daal::services::interface1::Status::Status
Status()
Definition: error_handling.h:497
daal::services::interface1::ErrorCollection::getDescription
const char * getDescription() const
Definition: error_handling.h:456
daal::services::interface1::Error
Class that represents an error.
Definition: error_handling.h:135
daal::services::interface1::ErrorCollection::add
void add(const KernelErrorCollectionPtr &e)
Definition: error_handling.h:408
daal::services::interface1::ErrorCollection
Class that represents an error collection.
Definition: error_handling.h:338
daal::services::interface1::ErrorCollection::setCanThrow
bool setCanThrow(bool bOn)
Definition: error_handling.h:472
daal::services::interface1::Error::details
const ErrorDetail * details() const
Definition: error_handling.h:204
daal::services::ErrorID
ErrorID
Definition: error_indexes.h:92
daal::services::interface1::Exception::getException
static Exception getException(const char *description)
Definition: error_handling.h:112
daal::services::interface1::SharedPtr< Error >
daal::services::interface1::ErrorCollection::add
void add(const ErrorCollection &e)
Definition: error_handling.h:391
daal::services::interface1::KernelErrorCollection::isEmpty
bool isEmpty() const
Definition: error_handling.h:282
daal::services::interface1::Exception::Exception
Exception(const char *description)
Definition: error_handling.h:83
daal::services::interface1::ErrorCollection::size
size_t size() const
Definition: error_handling.h:424
daal::services::interface1::KernelErrorCollection::KernelErrorCollection
KernelErrorCollection()
Definition: error_handling.h:245
daal::services::ErrorDetailID
ErrorDetailID
Definition: error_indexes.h:65
daal::services::interface1::ErrorCollection::isEmpty
bool isEmpty() const
Definition: error_handling.h:433
daal::services::interface1::Exception
Class that represents an exception.
Definition: error_handling.h:76
daal::services::interface1::String::c_str
const char * c_str() const
daal::services::interface1::ErrorCollection::ErrorCollection
ErrorCollection(const ErrorCollection &o)
Definition: error_handling.h:352
daal::services::interface1::Error::id
ErrorID id() const
Definition: error_handling.h:159
daal::services::interface1::ErrorCollection::canThrow
bool canThrow() const
Definition: error_handling.h:462
daal::services::interface1::ErrorCollection::ErrorCollection
ErrorCollection()
Definition: error_handling.h:346
daal::services::interface1::Exception::what
virtual const char * what() const
Definition: error_handling.h:89
daal::services::interface1::ErrorCollection::add
void add(const ErrorID &id)
Definition: error_handling.h:365
daal::algorithms::math::abs::value
Definition: abs_types.h:112
daal::services::interface1::ErrorCollection::ErrorCollection
ErrorCollection(const KernelErrorCollection &errors)
Definition: error_handling.h:359
daal::services::interface1::Exception::getException
static Exception getException(const String &description)
Definition: error_handling.h:102
daal::services::interface1::String
Class that implements functionality of the string, an object that represents a sequence of characters...
Definition: daal_string.h:69
daal::services::interface1::Error::setId
void setId(ErrorID id)
Definition: error_handling.h:165
daal::services::interface1::KernelErrorCollection
Class that represents a kernel error collection (collection that cannot throw exceptions) ...
Definition: error_handling.h:235
daal::services::interface1::Collection
Class that implements functionality of the Collection container.
Definition: collection.h:69