Handling Errors#

oneDAL provides classes and methods to handle exceptions or errors that can occur during library operation.

The methods of the library return the following computation set status:

  • Success - no errors detected

  • Warning - recoverable errors detected

  • Failure - unrecoverable errors detected

In oneDAL C++ interfaces, the base class for error handling is Status. If the execution of the library methods provided by the Algorithm or Data Management classes is unsuccessful, the Status object returned by the respective routines contains the list of errors and/or warnings extended with additional details about the error conditions. The class includes the list of the following methods for error processing:

  • ok() - checks whether the Status object contains any unrecoverable errors.

  • add() - adds information about the error, such as the error identifier or the pointer to the error.

  • getDescription() - returns the detailed description of the errors contained in the object.

  • clear() - removes information about the errors from the object.

The error class in oneDAL C++ interfaces is Error. This class contains an error message and details of the issue. For example, an Error object can store the number of the row in the NumericTable that caused the issue or a message that an SQL database generated to describe the reasons of an unsuccessful query. A single Error object can store the error description and an arbitrary number of details of various types: integer or double values or strings.

The class includes the list of the following methods for error processing:

  • id() - returns the identifier of the error.

  • setId() - sets the identifier of the error.

  • description() - returns the detailed description of the error.

  • add[Int|Double|String]Detail() adds data type-based details to the error.

  • create() - creates an instance of the Error class with the given set of arguments.

By default, the compute() method of the library algorithms throws run-time exception when error is detected. To prevent throwing any exceptions, call the computeNoThrow() method.

Service methods of the algorithms, such as setResult() and setPartialResult(), do not throw exceptions and return the status of the respective operation.

The methods of the Data Management classes do not throw exceptions and return the status of the respective operation.

Examples#

C++: