|
Errors emitted by ZCslSetError will raise an exception in the calling
CSL code:
C function
----------
ZExportAPI(void) myFunc(ZCslHandle csl)
{
char buf[20];
long bufsiz;
int argc;
bufsiz = sizeof(buf);
if ( ZCslGet(csl, "argCount", buf, &bufsiz) ) return;
argc = atoi(buf);
if (argc == 2) {
ZCslSetError("Error in myFunc:");
ZCslSetError("%%% argcount must be 1 or 3");
return;
} // if
...
} // myFunc
CSL program
-----------
#loadLibrary 'ZcSysLib'
#loadLibrary 'ZcMyLib'
main()
{
try { myFunc(1, 2); }
catch (var exc[]) {
sysLog('caught exception with '+sizeof(exc)+' line(s):');
for (var i = 0; i < sizeof exc; i++)
sysLog(exc[i]);
} // catch
} // main
Output when running:
--------------------
caught exception with 2 line(s):
Error in myFunc:
%%% argcount must be 1 or 3
Exceptions thrown in CSL will be returned as error by ZCslCall:
CSL Function
------------
test(const mode)
{
if (mode < 0 || mode > 3) {
const exc[2] = {
'error in test():',
'invalid mode:'+mode
};
throw exc;
} // if
....
} // test
C Code
------
...
static char *args[] = { "5" };
errs = ZCslCall(csl, module, "test", 1, args);
if (errs) {
// errs will be 1 and ZCslGetError(csl, 0,...)
// will return 'invalid mode:5'
...
|