« Return to Thread: Java exceptions and throws

Re: Java exceptions and throws

by wsfulton :: Rate this Message:

Reply to Author | View in Thread

John Heisey wrote:

> I have not figured out how to get the Java code to include the throws declaration.
>
> %extend CCdciStreamInterface {
>
>   ...
>
>   void write(char *BYTE, long off, long len)
>   {
>     int readTimeout = 2000;
>     ULONG cbWritten;
>     EError error = $self->Write((void *)&BYTE[off], (ULONG)len, cbWritten,
>                         (DWORD)readTimeout);
>     if(error != ESuccess)
>     {
>       // throw
>       char msg[20];
>       sprintf(&msg[0], "CDCI Error: %u", error);
>       SWIG_exception(SWIG_IOError, &msg[0]);
>     }
>     return;
>   }
>
> }
>
> Resulting Java code:
>
>   public final static native void CdciStreamInterface_write(long jarg1, CdciStreamInterface jarg1_, byte[] jarg2, int jarg3, int jarg4);
>
> And
>
>   public void write(byte[] BYTE, int off, int len) {
>     CdciControllerInterfacesJNI.CdciStreamInterface_write(swigCPtr, this, BYTE, off, len);
>   }
>
>
> How do I get swig to include the throws declaration to the Java functions?
Use %javaexception. See
http://www.swig.org/Doc1.3/Java.html#l#exception_handling

William

------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

 « Return to Thread: Java exceptions and throws