Nel codice che posto sotto ho un problema. Ci sono due righe che possono generare entrambe delle eccezioni IOException. Le righe sono socket=new Socket(InetAddress.getByName("localhost"),f.getPor t()) e output=new ObjectOutputStream(socket.getOutputStream()). Ecco mi servirebbe un modo per distinguere i due errori. Io pensavo che ogni eccezione fosse individuata da un codice e per questo ho messo un if nel blocco Exception per fare il controllo, ma ho controllato e non è questo il modo.
public void runClient(GUI frame){
FileConfig f=new FileConfig();
try{
frame.writeTextArea("Connessione con il server...");
f.readProperties();
socket=new Socket(InetAddress.getByName("localhost"),f.getPor t());
frame.writeTextArea("Connessione effettuata con successo");
output=new ObjectOutputStream(socket.getOutputStream());
output.flush();
output.flush();
input=new ObjectInputStream(socket.getInputStream());
String x=(String)input.readObject();
if(x.equals("OK"))
autorizzazione=true;
}catch (IOException e) {
System.err.println(());
if(e.hashCode()==281)
frame.writeTextArea("Connessione rifiutata");
else if(e.hashCode()==275)
System.err.println(e.getMessage());
}catch(Exception eof){
System.err.println(eof.getMessage());
}
}
tulipan

Rispondi quotando