It is possible to throw an IException within a C++ function and catch it in CSS: C++ function
------------
static IString myCppFunc(KCss* css)
{
int argc = css->get("argCount").asInt();
if (argc == 2)
throw IException("%%% argcount must be 1 or 3");
...
} // myCppFunction
CSS program
-----------
#loadLibrary 'KcSysLib.dll'
#loadLibrary 'KcMyLib.dll'
main()
{
try { myCppFunc(1, 2); }
catch (var exc[]) {
sysLog('cought exception with '+sizeof(exc)+' line(s):');
for (var i = 0; i < sizeof exc; i++)
sysLog(exc[i]);
} // catch
} // main
Output when running:
--------------------
cought exception with 1 line(s):
%%% argcount must be 1 or 3
The vice versa is also possible: CSS Function
------------
test(const mode)
{
if (mode < 0 || mode > 3) {
const exc[2] = {
'error in test():',
'invalid mode:'+mode
};
throw exc;
} // if
....
} // test
C++ Function
------------
void cppTest()
{
try {
KCss css;
css.loadScript("test.css");
IString ret = css.call("cppTest.exe","test",1,"5");
....
} // try
catch (IException err) {
for (int i = err.textCount()-1; i >= 0; i--)
cerr << err.text(i) << endl;
} // catch
} // cppTest
|