Archived

This forum has been archived. Please start a new discussion on GitHub.

How to catch ConnectionLostConnection exception in cpp?

Hello,

I've just started evaluation of Ice (cpp).
Ice runtime throws ConnectionLostConnection exception somewhere in its threads when connection is lost. What is supposed way to catch this exception?

Vitaly Berov

Comments

  • matthew
    matthew NL, Canada
    On the server side you cannot. What do you want to catch this for?
  • Now it doesn't break anything.
    It just seems strange to have uncaught exceptions in application - I'm afraid to have problems later (with functional tests auto runner of smth. else).
  • benoit
    benoit Rennes, France
    Hi,

    An Ice::ConnectionLostException exception indicates that the peer closed the connection.

    On the server side, it's raised by the Ice runtime and catched by the server thread pool which takes care of cleaning up the connection resources. There's nothing to worry about, you'll never have to catch it.

    On the client side, if the connection is closed by the peer while you're making an invocation, an Ice::ConnectionLostException might be raised and should be catch by your code like any other Ice::LocalException that an Ice invocation might raise.

    Cheers,
    Benoit.
  • Thanks for the comprehensive answer, Benoit. It became more clear now :)

    Vitaly Berov
  • Note that on the server side, you only get a warning about lost connections if you set Ice.Warn.Connections=1. If you don't want to see these warning, just use Ice.Warn.Connections=0.
  • help: how to catch ConnectionLostException at client?

    I've been wondering how to catch ConnectionLostException at client application.

    Here's a summary of what I'm doing:

    My server/client use bidirectional communication in a way that the sample codes ( Ice.bidir.client/server) do.
    If I terminates a server after a client connects to a server, the following warning is printed out (Ice.Warn.Connections = 1) :

    connection exception:
    TcpTransceiver.cpp:191: Ice::ConnectionLostException:
    connection lost: WSAECONNRESET

    The message above prints out as soon as a server terminates, i.e., a client is disconnected, but the thing is that I cannot catch that exception.

    Could you guide me how to catch it or more specifically, in which thread should I catch it? I want to use that exception in order to do some state initialization in my app.
    If you could explain it using Ice.bidir.server/client sample codes, it would be great.

    Thank you in advance. :)
  • benoit
    benoit Rennes, France
    Hi,

    There are no ways to catch this exception. It's in general not a good idea to rely on the Ice runtime to detect that the connection was lost since this isn't reliable (while it appears to work in your case, it might not if the client crashes and/or is behind multiple network routers). See also this FAQ on this subject. To setup/destroy state, I recommend using the session pattern instead, see demo/Ice/session for example and the links provided in the FAQ.

    Cheers,
    Benoit.