Sorry, this does not work.
Here's my changed sample code:
----
468: ConnectFuture future = null;
469: try {
470: future = connector.connect(new InetSocketAddress(host, port));
471: future.awaitUninterruptibly();
472: } catch (Exception e){
473: throw new EstablishConnectionFailed("Can't connect due to
unresolved socket address. host="+host+" port="+port+" error:
"+e.getMessage());
474: }
----
And the 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:470) <---- This is the line in
which the exception occurs
at de.root1.simon.Simon.lookup(Simon.java:322)
at SampleClient.main(SampleClient.java:86)
----
As you can see: The exception is is thrown at line 470, which is the line
with the connect() call. And the exception is not caught. So it's not up to
future.awaitUninterruptibly() to throw the exception.
Maybe you forgot that this only happens in case of a network problem, as i
described in my last mail.
br,
Alex
On Thu, 28 May 2009 13:04:44 +0200, Emmanuel Lecharny
<[email protected]>
wrote:
>
>
> 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.
> }
>
>
> 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?