On Thu, May 28, 2009 at 12:47 PM, Alexander Christian <[email protected]> wrote:

>
> Hi guys,
>
> I have a small problem.
>
> I have the following part of code:
>
> ----
> ConnectFuture future = null;
> try {
>        future = connector.connect(new InetSocketAddress(host, port));
> } catch (Exception e){
>        throw new EstablishConnectionFailed("Can't connect due to unresolved
> socket address. host="+host+" port="+port+" error: "+e.getMessage());
> }
> ----
>
> In case I used an IP adress and not an hostname (to prevent "unresolved xyz
> exceptions"), AND the current machine has some network problems (can be
> "simulated" by disabling the network-device in windows xp), I get the
> following exception:
>
> ----
> Exception in thread "main" java.nio.channels.UnresolvedAddressException
>        at sun.nio.ch.Net.checkAddress(Unknown Source)
>        at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
>        at
>
> org.apache.mina.transport.socket.nio.NioSocketConnector.connect(NioSocketConnector.java:188)
>        at
>
> org.apache.mina.transport.socket.nio.NioSocketConnector.connect(NioSocketConnector.java:46)
>        at
>
> org.apache.mina.core.polling.AbstractPollingIoConnector.connect0(AbstractPollingIoConnector.java:324)
>        at
>
> org.apache.mina.core.service.AbstractIoConnector.connect(AbstractIoConnector.java:256)
>        at
>
> org.apache.mina.core.service.AbstractIoConnector.connect(AbstractIoConnector.java:173)
>        at de.root1.simon.Simon.lookup(Simon.java:xxx)
>        at de.root1.simon.Simon.lookup(Simon.java:yyy)
>        at SampleClient.main(SampleClient.java:zzz)
> ----
>
> As you can see, I already build an "universal" try/catch block to catch
> this exception. But it doesn't matter what kind of exception I'm trying to
> catch (tried: java.nio.channels.UnresolvedAddressException,
> java.lang.RuntimeException and java.lang.Exception), I'm finally not able
> to catch the exception and "transform" it to my own exception
> (EstablishConnectionFailed).
>
> I'm using MINA 2.0.0M4 and JRE/JDK6U11 on Windows XP SP3.
> Any ideas on how to get the exception catched properly?


The connection is asynchronous, and you get a future as a reply to your
request. If you want to wait for the result, you must do something like :

try {
  future.awaitUninterruptibly
} catch ( Exception e ) {
  // You should get some exception here.
}


-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com

Reply via email to