"Ashish" <[EMAIL PROTECTED]> writes:

> how to close server socket without throwing an exception?
> 
> if i call close then it throws exception which gets caught in catch 1 not in catch 2
> can anybody explain

I tried it on JDK 1.1.7v3.  First, I did not get any exception that
you got.  Second, the program does not even go as far as the
ss.close() statement: it blocks at ss.accept() (which is correct
behaviour).  If I then have a client connect to the port this program
is listening to, then the program continues and runs to completion
without exception.

In other words, I cannot reproduce your result.

Complete program I used:

import java.io.*;
import java.net.*;

public class SS
{
  public static void main(String args[]) {
    ServerSocket ss = null;
    try
      {
        ss = new ServerSocket(3856);
      }
    catch (Exception e)
      {
        System.out.println("0");
      }

    try
      {
        ss.accept();
      }
    catch(Exception e) /* 1 */
      {
        System.out.println("1");
      }

    try
      {
        ss.close();
      }
    catch(Exception e) /* 2 */
      {
        System.out.println("2");
      }
  }
}

-- 
[If you post a response, no need to cc me; if you cc me, please say so.]
A compiler always tells the truth and calls a spade a spade.


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to