API 2.0 - using SocketCore.Error

I’ve subclassed SSLSocket, and I’m using AddHandler to add an error handler. Under API 1.0 my delegate method had the one parameter, the subclass. That has worked fine so far.

Under API 2.0, the error handler is defined as having a RuntimeException as a parameter, but I don’t seem to be able to declare that without the compiler complaining. A declaration like this, for instance:

Sub errorEvent (s as MySSLClass, e as RuntimeException)

used with AddHandler thus:

Addhandler me.Error, WeakAddressOf errorEvent

and the compiler complains that “this method requires more parameters than were passed” and about a delegate mismatch. I suppose my syntax is wrong somehow - can anyone advise?

Also: if I have an error handler handling errors, albeit passed as an exception, do I still need try/catch round socket actions?

Use two methods, one for each API, then put your AddHandler calls in a #If XojoVersion conditional.

I can’t find any way of making it compile in 2019r2 while passing a RuntimeException parameter to the error handler.

I am using the following:

#if XojoVersion >= 2019.02 then AddHandler mySocket.Error, WeakAddressOf mySocket_Error #else AddHandler mySocket.Error, WeakAddressOf mySocket_Error_Old #endif

Private Sub mySocket_Error(sender as TCPSocket, e as RuntimeException) End Sub

Private Sub mySocket_Error_Old(sender as TCPSocket) End Sub

But then you’d expect that, as I am only compiling this version under 2019r2, that this would compile OK:

But it doesn’t. I even put the conditional around the Addhandler just in case.

This is a documentation error. You should report it via Feedback. SSLSocket’s Error event signature is unchanged, and does not have an exception parameter in 2019R2.

You can quickly check things like this for yourself in the future by adding an instance of the class to a window then adding an event handler for the event you wish to look at.

Seems that it should have such a parameter, and that it doesn’t is a bug:

<https://xojo.com/issue/58066>