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 and
removeErrorSink member functions. Note that all errors raised by the underlying table object are forwarded to the data source error sinks. In addition, the data source itself can raise specific errors.
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
IliErrorReporter class. The
setErrorReporter member function can be used to provide a custom error reporter.
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. In such cases, the
dontValidateRow member function should be called to stop the validation process and errors can be raised by calling the
addErrorMessage member function. For more information on Error Messages, see
Error Messages.
Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.