%pragma(csharp) imclasscode=%{
  public class ParserException : Exception{
  	public ParserException(string msg):base(msg){
  	}
  }
  public class TokenManagerException : Exception{
  	public TokenManagerException(string msg):base(msg){
  	}
  }
  public class RAMTransactionException : Exception{
  	public RAMTransactionException(string msg):base(msg){
  	}
  }
  public class TooManyClausesException : Exception{
  	public TooManyClausesException(string msg):base(msg){
  	}
  }
  
  
  class CLuceneExceptionHelper {
    public delegate void CLuceneExceptionDelegate(string message,int code);
    static CLuceneExceptionDelegate exceptDelegate = new CLuceneExceptionDelegate(ThrowError);

    [DllImport("$dllimport", EntryPoint="CLuceneRegisterExceptCallback_$module")]
    public static extern void CLuceneRegisterExceptCallback_$module(CLuceneExceptionDelegate exceptDelegate);

    static void ThrowError(string cString, int cl_code) {
    	if ( cl_code == 1)
    		throw new System.IO.IOException(cString);
			else if ( cl_code == 2 )
				throw new NullReferenceException(cString);
			else if ( cl_code == 4 )
				throw new ArgumentException(cString);
			else if ( cl_code == 5)
				throw new ParserException(cString);
			else if ( cl_code == 6)
				throw new TokenManagerException(cString);
			else if ( cl_code ==  7)
				throw new NotSupportedException(cString);
			else if ( cl_code ==  8)
				throw new InvalidOperationException(cString);
			else if ( cl_code ==  9)
				throw new IndexOutOfRangeException(cString);
			else if ( cl_code ==  10)
				throw new TooManyClausesException(cString);
			else if ( cl_code ==  11)
				throw new RAMTransactionException(cString);
			else if ( cl_code ==  12 )
				throw new InvalidCastException(cString);
			else
			  throw new Exception(cString);
    }

    static CLuceneExceptionHelper() {
      CLuceneRegisterExceptCallback_$module(exceptDelegate);
    }
  }
  static CLuceneExceptionHelper clexceptHelper = new CLuceneExceptionHelper();

%}

%insert(runtime) %{
	typedef void (SWIGSTDCALL* SWIG_CLuceneExceptionCallback_t)(const char *,long code);
	static SWIG_CLuceneExceptionCallback_t CL_exceptCallback = NULL;

	#ifdef __cplusplus
	extern "C" 
	#endif
  DllExport void SWIGSTDCALL CLuceneRegisterExceptCallback_$module(SWIG_CLuceneExceptionCallback_t callback) {
	  CL_exceptCallback = callback;
	}
	
%}

