Errors are handled by examining the return values of the functions. The Cicode functions can be classified as regards their return value as follows:
Functions returning |
Calling functions should check for |
---|---|
Error code only |
0 no error (success) > 0 error code |
Handles |
-1 bad handle >= 0 valid handle |
Random values |
the return of IsError() |
The following Cicode functions can halt the current task:
DevOpen, DevHistory,
DevNext, DevPrev, DevSeek, DevFind, DevFlush, DevRecNo, DevRead,
DevReadLn, DevAppend, DevDelete, DevZap, DevControl , DevPrint ,
DevModify, ErrTrap; FileOpen, FileClose, FileReadBlock,
FileWriteBlock, FileSeek, FileDelete, FileReName, FileSize,
FileReadLn, FileCopy; FormNew; SQLConnect, SQLTraceOn, SQLTraceOff,
SQLErrMsg
.
If an error is detected in one of these functions, your Cicode task will generate a hardware error and be halted. You may stop your Cicode task from being halted by using the ErrSet() function and checking for errors using IsError().
The parameter [Code]HaltOnError
allows you to stop any errors
detected in these functions from halting your Cicode. If you set. .
.
[code]
HaltOnError=0
then your Cicode will continue to run after a hardware error is detected in these functions.
For example:
INT
FUNCTION
ExampleInit()
INT nError = 0;
nError = ExampleOpen("MyForm");
IF nError = 0 THEN
...
END
END
INT
FUNCTION
ExampleOpen(STRING sName)
INT nError = 0;
...
IF <an error has been detected> THEN
nError = 299;
END
RETURN nError;
END
INT
FUNCTION
ExampleInit()
INT hFile = BAD_HANDLE;
...
hFile = ExampleFileOpen("MyFile.txt");
IF hFile <> BAD_HANDLE THEN
...
END
END
FUNCTION
ExampleFileOpen(STRING sName)
INT hFile = BAD_HANDLE;
hFile = FileOpen(sName, "r+");
IF hFile = BAD_HANDLE THEN
hFile = FileOpen(sName, "r");
END
RETURN hFile;
END
INT
FUNCTION
ExampleInit()
INT nSamples = 0;
...
ErrSet(1);
nSamples = ExampleSamples();
IF IsError() = 0 THEN
...
END
ErrSet(0);
END
INT
FUNCTION
ExampleSamples()
INT nSamples = 0;
INT nError = 0;
...
ErrTrap(nError);
RETURN nSamples;
END
See Also