diff --git a/Doc/Manual/Contents.html b/Doc/Manual/Contents.html index 9a8d79ab7..c5b63fa3f 100644 --- a/Doc/Manual/Contents.html +++ b/Doc/Manual/Contents.html @@ -406,6 +406,7 @@
  • Handling C++ exceptions
  • Exception handlers for variables
  • Defining different exception handlers +
  • Special variables for %exception
  • Using The SWIG exception library
  • Object ownership and %newobject diff --git a/Doc/Manual/Customization.html b/Doc/Manual/Customization.html index 5d49b3d4d..e9d70e39a 100644 --- a/Doc/Manual/Customization.html +++ b/Doc/Manual/Customization.html @@ -17,6 +17,7 @@
  • Handling C++ exceptions
  • Exception handlers for variables
  • Defining different exception handlers +
  • Special variables for %exception
  • Using The SWIG exception library
  • Object ownership and %newobject @@ -66,7 +67,9 @@ handler. For example, you can specify the following:

    When defined, the code enclosed in braces is inserted directly into the low-level wrapper -functions. The special symbol $action gets replaced with the actual operation +functions. The special variable $action is one of a few +%exception special variable +supported and gets replaced with the actual operation to be performed (a function call, method invocation, attribute access, etc.). An exception handler remains in effect until it is explicitly deleted. This is done by using either %exception or %noexception with no code. For example: @@ -419,7 +422,95 @@ declarations. However, it never really worked that well and the new %exception directive is much better.

    -

    11.1.6 Using The SWIG exception library

    +

    11.1.6 Special variables for %exception

    + + +

    +The %exception directive supports a few special variables which are placeholders for +code substitution. +The following table shows the available special variables and details what the special +variables are replaced with. +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    $actionThe actual operation to be performed (a function call, method invocation, variable access, etc.)
    $symnameThe symbol name used internally by SWIG
    $overnameThe extra mangling used in the symbol name for overloaded method. Expands to nothing if the wrapped method is not overloaded.
    $wrapnameThe language specific wrapper name (usually a C function name exported from the shared object/dll)
    $declThe fully qualified C/C++ declaration of the method being wrapped without the return type
    $fulldeclThe fully qualified C/C++ declaration of the method being wrapped including the return type
    + +

    +The special variables are often used in situations where method calls are logged. Exactly which form of the method call needs logging is up to individual requirements, but the example code below shows all the possible expansions, plus how an exception message could be tailored to show the C++ method declaration: +

    + +
    +%exception Special::something {
    +  log("symname: $symname");
    +  log("overname: $overname");
    +  log("wrapname: $wrapname");
    +  log("decl: $decl");
    +  log("fulldecl: $fulldecl");
    +  try {
    +    $action
    +  } 
    +  catch (MemoryError) {
    +      croak("Out of memory in $decl");
    +  }
    +}
    +void log(const char *message);
    +struct Special {
    +  void something(const char *c);
    +  void something(int i);
    +};
    +
    + +

    +Below shows the expansions for the 1st of the overloaded something wrapper methods for Perl: +

    + +
    +  log("symname: Special_something");
    +  log("overname: __SWIG_0");
    +  log("wrapname: _wrap_Special_something__SWIG_0");
    +  log("decl: Special::something(char const *)");
    +  log("fulldecl: void Special::something(char const *)");
    +  try {
    +    (arg1)->something((char const *)arg2);
    +  } 
    +  catch (MemoryError) {
    +    croak("Out of memory in Special::something(char const *)");
    +  }
    +
    + + +

    11.1.7 Using The SWIG exception library