24 #ifndef __ERROR_HANDLING__
25 #define __ERROR_HANDLING__
27 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
31 #include "daal_string.h"
32 #include "error_indexes.h"
34 #include "services/collection.h"
46 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
52 struct DAAL_EXPORT Exception : std::exception
59 Exception(
const char *description) : _description(description) {};
65 virtual const char *what()
const throw() {
return _description.c_str(); };
71 virtual ~Exception() throw() {}
78 static Exception getException(
const String &description)
80 String d(description);
81 return Exception(d.c_str());
88 static Exception getException(
const char *description)
90 return Exception(description);
100 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
101 using interface1::Exception;
111 class DAAL_EXPORT Error
120 Error(
const ErrorID
id = NoErrorMessageFound);
126 Error(
const Error &e);
135 ErrorID id()
const {
return _id; }
141 void setId(ErrorID
id)
150 const char *description()
const;
158 Error &addIntDetail(ErrorDetailID
id,
int value);
166 Error &addDoubleDetail(ErrorDetailID
id,
double value);
174 Error &addStringDetail(ErrorDetailID
id,
const String &value);
180 const ErrorDetail *details()
const {
return _details; }
186 static SharedPtr<Error> create(ErrorID
id);
188 static SharedPtr<Error> create(ErrorID
id, ErrorDetailID det,
int value);
190 static SharedPtr<Error> create(ErrorID
id, ErrorDetailID det,
const String &value);
199 Error &addDetail(ErrorDetail *detail);
203 ErrorDetail *_details;
205 typedef SharedPtr<Error> ErrorPtr;
211 class DAAL_EXPORT KernelErrorCollection :
private Collection<SharedPtr<Error> >
216 typedef Collection<SharedPtr<Error> > super;
221 KernelErrorCollection() : _description(0) {}
227 KernelErrorCollection(
const KernelErrorCollection &other);
234 Error &add(
const ErrorID &
id);
240 void add(
const ErrorPtr &e);
246 void add(
const services::SharedPtr<KernelErrorCollection> &e);
252 void add(
const KernelErrorCollection &e);
258 bool isEmpty()
const {
return size() == 0; }
271 Error *at(
size_t index);
278 const Error *at(
size_t index)
const;
285 Error *operator[](
size_t index);
292 const Error *operator[](
size_t index)
const;
297 virtual ~KernelErrorCollection();
303 const char *getDescription()
const;
306 mutable char *_description;
308 typedef SharedPtr<KernelErrorCollection> KernelErrorCollectionPtr;
314 class DAAL_EXPORT ErrorCollection
322 ErrorCollection() : _errors(new KernelErrorCollection()), _canThrow(true){}
328 ErrorCollection(
const ErrorCollection &o) : _errors(o.getErrors()), _canThrow(o._canThrow) {}
335 explicit ErrorCollection(
const KernelErrorCollection &errors) : _errors(new KernelErrorCollection(errors)), _canThrow(true) {}
341 void add(
const ErrorID &
id)
344 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
346 throw Exception::getException(getDescription());
354 void add(
const ErrorPtr &e)
357 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
359 throw Exception::getException(getDescription());
367 void add(
const ErrorCollection &e)
371 _errors->add(e.getErrors());
372 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
374 throw Exception::getException(getDescription());
384 void add(
const KernelErrorCollectionPtr &e)
389 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
391 throw Exception::getException(getDescription());
402 return _errors->size();
411 return _errors->isEmpty();
417 virtual ~ErrorCollection() {}
423 const KernelErrorCollectionPtr &getErrors()
const
432 const char *getDescription()
const {
return _errors->getDescription(); }
438 bool canThrow()
const
448 bool setCanThrow(
bool bOn)
450 bool bVal = _canThrow;
456 KernelErrorCollectionPtr _errors;
459 typedef SharedPtr<ErrorCollection> ErrorCollectionPtr;
467 class DAAL_EXPORT Status
473 Status() : _impl(0){}
483 Status(
const ErrorPtr& e);
488 Status(
const Status& other);
499 bool ok()
const {
return !_impl; }
505 operator bool()
const {
return ok(); }
512 Status& add(ErrorID
id);
519 Status& add(
const ErrorPtr& e);
526 Status& add(
const Status& other);
533 Status& operator |=(
const Status& other) {
return add(other); }
540 Status& operator =(
const Status& other);
546 const char* getDescription()
const;
557 DAAL_DEPRECATED Status(
const KernelErrorCollection& e);
561 DAAL_DEPRECATED Status(
const ErrorCollection& e);
566 ErrorCollectionPtr getCollection()
const;
572 inline const Status& throwIfPossible(
const Status& s)
574 #if (!defined(DAAL_NOTHROW_EXCEPTIONS))
576 throw services::Exception::getException(s.getDescription());
582 using interface1::Error;
583 using interface1::KernelErrorCollection;
584 using interface1::ErrorCollection;
585 using interface1::ErrorPtr;
586 using interface1::KernelErrorCollectionPtr;
587 using interface1::ErrorCollectionPtr;
588 using interface1::Status;
589 using interface1::throwIfPossible;
591 inline Status checkForNullByteInjection(
const char *begin,
const char *
const end)
593 for (; begin != end; ++begin)
597 return Status(ErrorNullByteInjection);
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:467
daal::services::interface1::Collection
Class that implements functionality of the Collection container.
Definition: collection.h:45
daal::services::interface1::KernelErrorCollection::isEmpty
bool isEmpty() const
Definition: error_handling.h:258
daal::services::interface1::KernelErrorCollection
Class that represents a kernel error collection (collection that cannot throw exceptions) ...
Definition: error_handling.h:211
daal::services::interface1::Error::details
const ErrorDetail * details() const
Definition: error_handling.h:180
daal::services::interface1::ErrorCollection::isEmpty
bool isEmpty() const
Definition: error_handling.h:409
daal::services::interface1::ErrorCollection::add
void add(const ErrorCollection &e)
Definition: error_handling.h:367
daal::services::interface1::ErrorCollection::add
void add(const KernelErrorCollectionPtr &e)
Definition: error_handling.h:384
daal::services::interface1::Exception::getException
static Exception getException(const String &description)
Definition: error_handling.h:78
daal::services::interface1::Error::setId
void setId(ErrorID id)
Definition: error_handling.h:141
daal::services::interface1::ErrorCollection::add
void add(const ErrorID &id)
Definition: error_handling.h:341
daal::services::interface1::ErrorCollection::canThrow
bool canThrow() const
Definition: error_handling.h:438
daal::services::interface1::Exception::what
virtual const char * what() const
Definition: error_handling.h:65
daal::services::interface1::ErrorCollection::~ErrorCollection
virtual ~ErrorCollection()
Definition: error_handling.h:417
daal::services::interface1::Status::Status
Status()
Definition: error_handling.h:473
daal::services::interface1::ErrorDetail
Base for error detail classes.
Definition: error_id.h:46
daal::services::ErrorNullByteInjection
Definition: error_indexes.h:394
daal::services::interface1::KernelErrorCollection::KernelErrorCollection
KernelErrorCollection()
Definition: error_handling.h:221
daal::services::interface1::String::c_str
const char * c_str() const
daal::services::interface1::Exception::getException
static Exception getException(const char *description)
Definition: error_handling.h:88
daal::services::interface1::Error::id
ErrorID id() const
Definition: error_handling.h:135
daal::services::interface1::SharedPtr< Error >
daal::services::interface1::ErrorCollection::getDescription
const char * getDescription() const
Definition: error_handling.h:432
daal::services::NoErrorMessageFound
Definition: error_indexes.h:418
daal::services::interface1::ErrorCollection::setCanThrow
bool setCanThrow(bool bOn)
Definition: error_handling.h:448
daal::services::interface1::ErrorCollection::size
size_t size() const
Definition: error_handling.h:400
daal::services::interface1::ErrorCollection::ErrorCollection
ErrorCollection()
Definition: error_handling.h:322
daal::services::interface1::Error
Class that represents an error.
Definition: error_handling.h:111
daal::services::interface1::Exception::Exception
Exception(const char *description)
Definition: error_handling.h:59
daal::services::interface1::ErrorCollection::add
void add(const ErrorPtr &e)
Definition: error_handling.h:354
daal::services::interface1::Exception::~Exception
virtual ~Exception()
Definition: error_handling.h:71
daal::services::interface1::ErrorCollection::getErrors
const KernelErrorCollectionPtr & getErrors() const
Definition: error_handling.h:423
daal::services::interface1::Exception
Class that represents an exception.
Definition: error_handling.h:52
daal::services::interface1::ErrorCollection::ErrorCollection
ErrorCollection(const ErrorCollection &o)
Definition: error_handling.h:328
daal::services::interface1::ErrorCollection::ErrorCollection
ErrorCollection(const KernelErrorCollection &errors)
Definition: error_handling.h:335
daal::services::interface1::String
Class that implements functionality of the string, an object that represents a sequence of characters...
Definition: daal_string.h:46
daal::algorithms::math::abs::value
Definition: abs_types.h:88
daal::services::interface1::Status::ok
bool ok() const
Definition: error_handling.h:499
daal::services::interface1::ErrorCollection
Class that represents an error collection.
Definition: error_handling.h:314
daal::services::ErrorID
ErrorID
Definition: error_indexes.h:68
daal::services::ErrorDetailID
ErrorDetailID
Definition: error_indexes.h:41