Error Handling
This section provides information on three topics concerning the handling of errors for a data source: error catching, error reporting, and error raising.
Error Catching
Errors can be caught through error sink objects using a similar technique to the one described for IliTable objects. See the addErrorSink
The following example shows how a data source should be set up in order to catch and report errors:
IliDataSource* ds;
...
// Set up an error sink.
IliErrorList errors;
ds->addErrorSink(&errors);
// Act on the data source.
ds->gotoRow(10);
ds->setValue(“NAME”, IliValue(“Smith”));
ds->validate();
...
ds->removeErrorSink(&errors);
// Check for errors.
if (errors.getErrorsCount() > 0) {
ds->reportErrors(errors);
}
Error Reporting
Errors are reported through an instance of the class. The setErrorReporter
The following example shows how the error reporter of a data source can be redefined:
class MyErrorReporter: public IliErrorReporter {
public:
virtual void reportErrors (IlvDisplay* dpy,
IlvAbstractView* anchor,
const IliErrorList& errors) const {
for (IlInt i = 0; i < errors.getErrorsCount(); ++i) {
IlvPrint(“Error: %s”, errors.at(i).getMessage());
}
}
};
int main(int argc, char** argv) {
IliDataSource* ds;
...
MyErrorReporter* rep = new MyErrorReporter;
ds->setErrorReporter(rep);
...
}
Error Raising
Errors can be raised within a validation callback such as ValidateRow, PrepareUpdate or PrepareInsert