how should i know which exception should i catch?

hey all....

i am getting the following error msgs (everything is compiled just fine..)

I successfully translated the word car to αυτοκίνητο

15 Δεκ 2006 5:28:40 μμ com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl <init>

WARNING:"IOP00410201: (COMM_FAILURE) Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: 10.34.153.11; port: 1541"

org.omg.CORBA.COMM_FAILURE:vmcid: SUN minor code: 201 completed: No

at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(Unknown Source)

at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(Unknown Source)

at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(Unknown Source)

at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(Unknown Source)

at com.sun.corba.se.impl.transport.SocketOrChannelContactInfoImpl.createConnection(Unknown Source)

at com.sun.corba.se.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(Unknown Source)

at com.sun.corba.se.impl.protocol.CorbaClientDelegateImpl.request(Unknown Source)

at org.omg.CORBA.portable.ObjectImpl._request(Unknown Source)

at WorkflowFramework._ServiceStub.translationService(_ServiceStub.java:18)

at wF.ServantEnglishToGreek.translationService(ServantEnglishToGreek.java:294)

at WorkflowFramework._ServiceImplBase._invoke(_ServiceImplBase.java:41)

at com.sun.corba.se.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(Unknown Source)

at com.sun.corba.se.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(Unknown Source)

at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(Unknown Source)

at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(Unknown Source)

at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleInput(Unknown Source)

at com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(Unknown Source)

at com.sun.corba.se.impl.protocol.CorbaMessageMediatorImpl.handleRequest(Unknown Source)

at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.dispatch(Unknown Source)

at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.doWork(Unknown Source)

at com.sun.corba.se.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(Unknown Source)

Caused by: java.net.ConnectException: Connection refused: connect

at sun.nio.ch.Net.connect(Native Method)

at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)

at java.nio.channels.SocketChannel.open(Unknown Source)

at com.sun.corba.se.impl.transport.DefaultSocketFactoryImpl.createSocket(Unknown Source)

... 19 more

NEXT SERVER IS DOWN! org.omg.CORBA.COMM_FAILURE:vmcid: SUN minor code: 201 completed: No

when i am running a function on a remote object reference

i have catched the exception and that is why the msg NEXT SERVER IS DOWN is printed..but how can i handle all the previous msgs?

i searched a lot on the internet and i cannot find how to catch this error...

all these msg seem to come from the java.net.ConnectException: Connection refused: connect but i dont have any statement that i can include in a catch try block so that i can do sth with that..(maybe print a msg..)

btw the line from my code that this msg is refering to is the following

try{

//call next server

nextServerRef.translationService(objRef, buffer);

}

// catch(java.net.ConnectException e){

catch(Exception e){

System.out.println("NEXT SERVER IS DOWN! "+e);

}

and btw i cannot include this code to the ConnectException because it keeps complaining that this code cannot throw this exception....

any advice?

ps.i have posted a specific msg to the rmi subforum...but i am trying to undestand the general process ..to look the wood not the trees;-)

[4365 byte] By [panosjavaa] at [2007-11-26 12:44:53]
# 1

try{

//call next server

nextServerRef.translationService(objRef, buffer);

}

// catch(java.net.ConnectException e){

catch(Exception e){

System.out.println("NEXT SERVER IS DOWN! "+e);

}

You can't catch the ConnectException because the method translationService does not throw this exception. If you want to catch a ConnectionException, you need to declare that method to throw java.net.ConnectException.

Also, it would be better form in the catch block, instead of printing e, to instead do a e.printStackTrace() to get the entire call stack dumped

~Tim

SomeoneElsea at 2007-7-7 16:23:06 > top of Java-index,Java Essentials,New To Java...
# 2
the thing is that even if i catch it as a generic Exception i still get all the messages to the client and is sth that I do not what to happen... i want to be able to apear an error msg like next server is down and nothing else....
panosjavaa at 2007-7-7 16:23:06 > top of Java-index,Java Essentials,New To Java...
# 3
I am guessing that throwing the exception, combined with chaining exceptions, as illustrated in the tutorial can be used to do what you want: http://java.sun.com/docs/books/tutorial/essential/exceptions/chained.html
ChuckBinga at 2007-7-7 16:23:06 > top of Java-index,Java Essentials,New To Java...
# 4

hmm thx for the help...the thing is that i cannot avoid taking these messages even if i catch the most general exception (Exception e)..i still get these messages on the client..(if a service is unabailable...)

how can i check what exception throws these msgs so that i can catch them and not appear them to the client?

thx for the tutorial...

panosjavaa at 2007-7-7 16:23:06 > top of Java-index,Java Essentials,New To Java...
# 5
I wonder if these are in fact warning messages being printed out to System.err by some debugging or tracing routine.Try redirecting System.err and see what happens. Also see if there are any tracing or debugging options that you can turn off.
cotton.ma at 2007-7-7 16:23:06 > top of Java-index,Java Essentials,New To Java...
# 6
hmm...can you help me on that? because i dont know how can i do that://how can i redirect System.err or turning off tracing or debugging?btw these should not be seen to the client..(and i dont want him to deactivate things to his jre..)...
panosjavaa at 2007-7-7 16:23:06 > top of Java-index,Java Essentials,New To Java...
# 7
> hmm...can you help me on that? because i dont know> how can i do that://> > how can i redirect System.err The java.lang.System class has a static method named setErr which allows you to redirect the error output stream.
cotton.ma at 2007-7-7 16:23:06 > top of Java-index,Java Essentials,New To Java...
# 8

If the runtime exception occurs in a method that doesn't either catch it or declare it as being thrown, and you can't change the method, then there's not much you can do except diverting the output to a non-visible location, or a null sink.

If you can change the method, you can either catch the exception and substitute your message, or you can change it to throw the method, and then catch the exception in a higher enclosing method, as I show:

public static void main(String[] args)

{

try

{

some_method();

}

catch (ConnectException ce)

{

System.out.println("NEXT SERVER IS DOWN");

}

}

static void some_method() throws ConnectException

{

throw new ConnectException(); // create the exception

}

ChuckBinga at 2007-7-7 16:23:06 > top of Java-index,Java Essentials,New To Java...