访问套接字时出现异常错误的问题

时间:2011-10-07 18:58:42

标签: android sockets exception exception-handling

我玩简单的套接字编程。当我用错误的IP地址运行它时我遇到的问题它只是用力关闭炸弹,即使我试图捕获所有错误。我可以检查是否还有其他异常错误?

    try {

        String SocketIP = Global.privateSocketIP;
        String SocketPort = Global.privateSocketPort;




        int SocketPrt = Integer.parseInt(SocketPort);

                SocketAddress adr = new InetSocketAddress(SocketIP,SocketPrt);
                CommSocket.connect(adr, 4000);



        CommDataOutput = new PrintWriter(new BufferedWriter(new OutputStreamWriter(CommSocket.getOutputStream())), true);
            CommDataInput = new BufferedReader(new InputStreamReader(
                CommSocket.getInputStream()));
        return "0";
    } catch (SocketTimeoutException e) {
        //String Timeout = e.getMessage();

        return "1";
    } catch (UnknownHostException e) {
        System.err.println("Don't know about host.");
        return "2";
    } catch (IOException e) {
        String neil = e.getMessage();
        neil = neil + "";
        System.err.println("Couldn't get I/O for "
                           + "the connection to host.");
        return "3";
    } catch (Exception exc)
    {
        String mes = exc.getMessage();
        mes = mes + "";
        return "3";
    }

0 个答案:

没有答案