22 #ifndef __ERROR_HANDLING__
23 #define __ERROR_HANDLING__
25 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
29 #include "daal_string.h"
30 #include "error_indexes.h"
32 #include "services/collection.h"
44 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
50 struct DAAL_EXPORT Exception : std::exception
57 Exception(
const char *description) : _description(description) {};
63 virtual const char *what()
const throw() {
return _description.c_str(); };
69 virtual ~Exception() throw() {}
76 static Exception getException(
const String &description)
78 String d(description);
79 return Exception(d.c_str());
86 static Exception getException(
const char *description)
88 return Exception(description);
98 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
99 using interface1::Exception;
109 class DAAL_EXPORT Error
118 Error(
const ErrorID
id = NoErrorMessageFound);
124 Error(
const Error &e);
133 ErrorID id()
const {
return _id; }
139 void setId(ErrorID
id)
148 const char *description()
const;
156 Error &addIntDetail(ErrorDetailID
id,
int value);
164 Error &addDoubleDetail(ErrorDetailID
id,
double value);
172 Error &addStringDetail(ErrorDetailID
id,
const String &value);
178 const ErrorDetail *details()
const {
return _details; }
184 static SharedPtr<Error> create(ErrorID
id);
186 static SharedPtr<Error> create(ErrorID
id, ErrorDetailID det,
int value);
188 static SharedPtr<Error> create(ErrorID
id, ErrorDetailID det,
const String &value);
197 Error &addDetail(ErrorDetail *detail);
201 ErrorDetail *_details;
203 typedef SharedPtr<Error> ErrorPtr;
209 class DAAL_EXPORT KernelErrorCollection :
private Collection<SharedPtr<Error> >
214 typedef Collection<SharedPtr<Error> > super;
219 KernelErrorCollection() : _description(0) {}
225 KernelErrorCollection(
const KernelErrorCollection &other);
232 Error &add(
const ErrorID &
id);
238 void add(
const ErrorPtr &e);
244 void add(
const services::SharedPtr<KernelErrorCollection> &e);
250 void add(
const KernelErrorCollection &e);
256 bool isEmpty()
const {
return size() == 0; }
269 Error *at(
size_t index);
276 const Error *at(
size_t index)
const;
283 Error *operator[](
size_t index);
290 const Error *operator[](
size_t index)
const;
295 virtual ~KernelErrorCollection();
301 const char *getDescription()
const;
304 mutable char *_description;
306 typedef SharedPtr<KernelErrorCollection> KernelErrorCollectionPtr;
312 class DAAL_EXPORT ErrorCollection
320 ErrorCollection() : _errors(new KernelErrorCollection()), _canThrow(true){}
326 ErrorCollection(
const ErrorCollection &o) : _errors(o.getErrors()), _canThrow(o._canThrow) {}
333 explicit ErrorCollection(
const KernelErrorCollection &errors) : _errors(new KernelErrorCollection(errors)), _canThrow(true) {}
339 void add(
const ErrorID &
id)
342 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
344 throw Exception::getException(getDescription());
352 void add(
const ErrorPtr &e)
355 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
357 throw Exception::getException(getDescription());
365 void add(
const ErrorCollection &e)
369 _errors->add(e.getErrors());
370 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
372 throw Exception::getException(getDescription());
382 void add(
const KernelErrorCollectionPtr &e)
387 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
389 throw Exception::getException(getDescription());
400 return _errors->size();
409 return _errors->isEmpty();
415 virtual ~ErrorCollection() {}
421 const KernelErrorCollectionPtr &getErrors()
const
430 const char *getDescription()
const {
return _errors->getDescription(); }
436 bool canThrow()
const
446 bool setCanThrow(
bool bOn)
448 bool bVal = _canThrow;
454 KernelErrorCollectionPtr _errors;
457 typedef SharedPtr<ErrorCollection> ErrorCollectionPtr;
465 class DAAL_EXPORT Status
471 Status() : _impl(0){}
481 Status(
const ErrorPtr& e);
486 Status(
const Status& other);
497 bool ok()
const {
return !_impl; }
503 operator bool()
const {
return ok(); }
510 Status& add(ErrorID
id);
517 Status& add(
const ErrorPtr& e);
524 Status& add(
const Status& other);
531 Status& operator |=(
const Status& other) {
return add(other); }
538 Status& operator =(
const Status& other);
544 const char* getDescription()
const;
555 DAAL_DEPRECATED Status(
const KernelErrorCollection& e);
559 DAAL_DEPRECATED Status(
const ErrorCollection& e);
564 ErrorCollectionPtr getCollection()
const;
570 inline const Status& throwIfPossible(
const Status& s)
572 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
574 throw services::Exception::getException(s.getDescription());
580 using interface1::Error;
581 using interface1::KernelErrorCollection;
582 using interface1::ErrorCollection;
583 using interface1::ErrorPtr;
584 using interface1::KernelErrorCollectionPtr;
585 using interface1::ErrorCollectionPtr;
586 using interface1::Status;
587 using interface1::throwIfPossible;
daal::services::interface1::ErrorDetail
Base for error detail classes.
Definition: error_id.h:44
daal::services::interface1::ErrorCollection::add
void add(const ErrorPtr &e)
Definition: error_handling.h:352
daal::services::NoErrorMessageFound
Definition: error_indexes.h:406
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:465
daal
Definition: algorithm_base_common.h:31
daal::services::interface1::Exception::~Exception
virtual ~Exception()
Definition: error_handling.h:69
daal::services::interface1::ErrorCollection::getErrors
const KernelErrorCollectionPtr & getErrors() const
Definition: error_handling.h:421
daal::services::interface1::Status::ok
bool ok() const
Definition: error_handling.h:497
daal::services::interface1::ErrorCollection::~ErrorCollection
virtual ~ErrorCollection()
Definition: error_handling.h:415
daal::services::interface1::Status::Status
Status()
Definition: error_handling.h:471
daal::services::interface1::ErrorCollection::getDescription
const char * getDescription() const
Definition: error_handling.h:430
daal::services::interface1::Error
Class that represents an error.
Definition: error_handling.h:109
daal::services::interface1::ErrorCollection::add
void add(const KernelErrorCollectionPtr &e)
Definition: error_handling.h:382
daal::services::interface1::ErrorCollection
Class that represents an error collection.
Definition: error_handling.h:312
daal::services::interface1::ErrorCollection::setCanThrow
bool setCanThrow(bool bOn)
Definition: error_handling.h:446
daal::services::interface1::Error::details
const ErrorDetail * details() const
Definition: error_handling.h:178
daal::services::ErrorID
ErrorID
Definition: error_indexes.h:66
daal::services::interface1::Exception::getException
static Exception getException(const char *description)
Definition: error_handling.h:86
daal::services::interface1::SharedPtr< Error >
daal::services::interface1::ErrorCollection::add
void add(const ErrorCollection &e)
Definition: error_handling.h:365
daal::services::interface1::KernelErrorCollection::isEmpty
bool isEmpty() const
Definition: error_handling.h:256
daal::services::interface1::Exception::Exception
Exception(const char *description)
Definition: error_handling.h:57
daal::services::interface1::ErrorCollection::size
size_t size() const
Definition: error_handling.h:398
daal::services::interface1::KernelErrorCollection::KernelErrorCollection
KernelErrorCollection()
Definition: error_handling.h:219
daal::services::ErrorDetailID
ErrorDetailID
Definition: error_indexes.h:39
daal::services::interface1::ErrorCollection::isEmpty
bool isEmpty() const
Definition: error_handling.h:407
daal::services::interface1::Exception
Class that represents an exception.
Definition: error_handling.h:50
daal::services::interface1::String::c_str
const char * c_str() const
daal::services::interface1::ErrorCollection::ErrorCollection
ErrorCollection(const ErrorCollection &o)
Definition: error_handling.h:326
daal::services::interface1::Error::id
ErrorID id() const
Definition: error_handling.h:133
daal::services::interface1::ErrorCollection::canThrow
bool canThrow() const
Definition: error_handling.h:436
daal::services::interface1::ErrorCollection::ErrorCollection
ErrorCollection()
Definition: error_handling.h:320
daal::services::interface1::Exception::what
virtual const char * what() const
Definition: error_handling.h:63
daal::services::interface1::ErrorCollection::add
void add(const ErrorID &id)
Definition: error_handling.h:339
daal::algorithms::math::abs::value
Definition: abs_types.h:86
daal::services::interface1::ErrorCollection::ErrorCollection
ErrorCollection(const KernelErrorCollection &errors)
Definition: error_handling.h:333
daal::services::interface1::Exception::getException
static Exception getException(const String &description)
Definition: error_handling.h:76
daal::services::interface1::String
Class that implements functionality of the string, an object that represents a sequence of characters...
Definition: daal_string.h:44
daal::services::interface1::Error::setId
void setId(ErrorID id)
Definition: error_handling.h:139
daal::services::interface1::KernelErrorCollection
Class that represents a kernel error collection (collection that cannot throw exceptions) ...
Definition: error_handling.h:209
daal::services::interface1::Collection
Class that implements functionality of the Collection container.
Definition: collection.h:43