Error Messages Appear Even After Turning Off
Article ID: C01124
Last updated: 2007/04/11
|
Symptom
After the application initializes CodeBase, the application attempts
to suppress error messages by setting CODE4.errOff
to true. Even so, some CodeBase functions generate an error message.
Explanation
When CodeBase generates an error and CodeBase does
not have access to the CODE4
object, CodeBase always generates an error message.
This most commonly happens when an application does not perform
sufficient error checking. Consider the following sample code.
CODE4 cb;
DATA4 *data;
FIELD4 *field;
code4init(&cb);
cb.errOff = 1;
data = d4open(&cb, "this_does_not_exist.dbf");
field = d4field(data, "last_name");
In this sample code, d4open fails and
CodeBase will not display an error message. This is because
d4open is passed the CODE4
pointer and can see the errOff flag.
However, because this sample code does not check whether
d4open was successful, the code is allowed to call
d4field, passing the null pointer that was returned
by d4open. When d4field
receives this invalid parameter, it must generate an error, and because this
pointer is null, d4field has no way to see the
CODE4 object and the errOff flag.
Therefore, d4field displays an error message.
Solution
Do not allow an invalid parameter to be passed to a function. Proper
error checking would look like the following sample code.
CODE4 cb;
DATA4 *data;
FIELD4 *field;
code4init(&cb);
cb.errOff = 1;
data = d4open(&cb, "this_does_not_exist.dbf");
if (data)
{
field = d4field(data, "last_name");
|