I am having problem with respect to exception handling:

In my class two functions are throwing exceptions:

so the corresponding swig file is as follows:

========================================================
%module SnaccWrapper

%{
#include "IntermediateAsnMessage.hpp"
#include "SnaccIntf.hpp"
#include "SnaccIntfException.hpp"
#include "InvalidInputParameter.hpp"
#include "EncodeMsgException.hpp"
#include "DecodeMsgException.hpp"
%}

%include "std_string.i"
%include "arrays_java.i"

%inline%{

int CSnaccIntf::encodeMessage(CIntermediateAsnMessage *);

CIntermediateAsnMessage* CSnaccIntf::decodeMessage(signed char pacStream[] , int iLength);

int CSnaccIntf::fillStream(signed char acEncodedStream[ ], int iLength);

%}

%typemap(javabase) CSnaccIntfException "java.lang.Exception";
%typemap(javacode) CSnaccIntfException %{

  public String getMessage() {
    return getErrorMessage();
  }
%}

%javaexception("com.siemens.pa.ifupc.service.asn.CEncodeMsgException, com.siemens.pa.ifupc.service.asn.CInvalidInputParameter") CSnaccIntf::encodeMessgae {
  try
  {
     $action
  }
  catch (CEncodeMsgException &e) {
    jclass clazz = jenv->FindClass("com/siemens/pa/ifupc/service/asn/CEncodeMsgException");
    if(! clazz)
      return $null;

    jmethodID ctorID = jenv->GetMethodID(clazz, "<init>", "(ILjava/lang/String;)V");
   
    if (!ctorID) {
            return $null;
        }
    jstring excMessage = jenv->NewStringUTF(e.getErrorMessage().c_str());

    jobject excObject = jenv->NewObject(clazz,ctorID,e.getErrorId(),excMessage);

    jenv->Throw((jthrowable)excObject);
       
    return $null;
  }
  catch (CInvalidInputParameter &e) {
    jclass clazz = jenv->FindClass("com/siemens/pa/ifupc/service/asn/CInvalidInputParameter");
    if(! clazz)
      return $null;

    jmethodID ctorID = jenv->GetMethodID(clazz, "<init>", "(ILjava/lang/String;)V");
   
    if (!ctorID) {
            return $null;
        }
    jstring excMessage = jenv->NewStringUTF(e.getErrorMessage().c_str());

    jobject excObject = jenv->NewObject(clazz,ctorID,e.getErrorId(),excMessage);

    jenv->Throw((jthrowable)excObject);
       
    return $null;
  }
}

%javaexception("com.siemens.pa.ifupc.service.asn.CDecodeMsgException, com.siemens.pa.ifupc.service.asn.CInvalidInputParameter") CSnaccIntf::decodeMessage {
  try
  {
     $action
  }
  catch (CEncodeMsgException &e) {
    jclass clazz = jenv->FindClass("com/siemens/pa/ifupc/service/asn/CDecodeMsgException");
    if(! clazz)
      return $null;

    jmethodID ctorID = jenv->GetMethodID(clazz, "<init>", "(ILjava/lang/String;)V");
   
    if (!ctorID) {
            return $null;
        }
    jstring excMessage = jenv->NewStringUTF(e.getErrorMessage().c_str());

    jobject excObject = jenv->NewObject(clazz,ctorID,e.getErrorId(),excMessage);

    jenv->Throw((jthrowable)excObject);
       
    return $null;
  }
  catch (CInvalidInputParameter &e) {
    jclass clazz = jenv->FindClass("com/siemens/pa/ifupc/service/asn/CInvalidInputParameter");
    if(! clazz)
      return $null;

    jmethodID ctorID = jenv->GetMethodID(clazz, "<init>", "(ILjava/lang/String;)V");
   
    if (!ctorID) {
            return $null;
        }
    jstring excMessage = jenv->NewStringUTF(e.getErrorMessage().c_str());

    jobject excObject = jenv->NewObject(clazz,ctorID,e.getErrorId(),excMessage);

    jenv->Throw((jthrowable)excObject);
       
    return $null;
  }
}

%include "IntermediateAsnMessage.hpp"
%include "SnaccIntf.hpp"
%include "SnaccIntfException.hpp"
%include "InvalidInputParameter.hpp"
%include "EncodeMsgException.hpp"
%include "DecodeMsgException.hpp"


========================================================

But in my jni files re-throw of exception is implemented only in case of decode message method
the jni code is as follows:

 public int encodeMessage(CIntermediateAsnMessage arg0) {
 /////////////
}


public CIntermediateAsnMessage decodeMessage(byte[] arg0, int arg1) throws com.siemens.pa.ifupc.service.asn.CDecodeMsgException, com.siemens.pa.ifupc.service.asn.CInvalidInputParameter {
///////////////////
}

please tell me what mistake am i doing here.


thanks and regards


Here¢s a new way to find what you're looking for - Yahoo! Answers