Between CSS And C++ API

C Styled Script
Reference Manual

<< Back  End  Next >>
 
 
INDEX
Introduction
Installation
Using The CSS Executive
Language
   Comments
   Literals
   Var And Const
   Operators
   Statements And blocks
   Program Flow
   Exception Handling
      Between CSS And C API
      Between CSS And C++ API
   Functions
   Predefined Identifiers
Directives
System Library
String Library
Regular Expression Lib.
File Library
Database Library
C API
C++ API
CSS Links
  

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
 Copyright © IBK LandquartLast revised by Peter Koch, 24.02.00<< Back  Top  Next >>