KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > socks > SocksException


1 package socks;
2
3 /**
4  Exception thrown by various socks classes to indicate errors
5  with protocol or unsuccessfull server responses.
6 */

7 public class SocksException extends java.io.IOException JavaDoc{
8    /**
9     Construct a SocksException with given errorcode.
10     <p>
11     Tries to look up message which corresponds to this error code.
12     @param errCode Error code for this exception.
13    */

14    public SocksException(int errCode){
15        this.errCode = errCode;
16        if((errCode >> 16) == 0){
17           //Server reply error message
18
errString = errCode <= serverReplyMessage.length ?
19                       serverReplyMessage[errCode] :
20                       UNASSIGNED_ERROR_MESSAGE;
21        }else{
22           //Local error
23
errCode = (errCode >> 16) -1;
24           errString = errCode <= localErrorMessage.length ?
25                       localErrorMessage[errCode] :
26                       UNASSIGNED_ERROR_MESSAGE;
27        }
28    }
29    /**
30     Constructs a SocksException with given error code and message.
31     @param errCode Error code.
32     @param errString Error Message.
33    */

34    public SocksException(int errCode,String JavaDoc errString){
35        this.errCode = errCode;
36        this.errString = errString;
37    }
38    /**
39     Get the error code associated with this exception.
40     @return Error code associated with this exception.
41    */

42    public int getErrorCode(){
43       return errCode;
44    }
45    /**
46     Get human readable representation of this exception.
47     @return String represntation of this exception.
48    */

49    public String JavaDoc toString(){
50       return errString;
51    }
52
53    static final String JavaDoc UNASSIGNED_ERROR_MESSAGE =
54                   "Unknown error message";
55    static final String JavaDoc serverReplyMessage[] = {
56                   "Succeeded",
57                   "General SOCKS server failure",
58                   "Connection not allowed by ruleset",
59                   "Network unreachable",
60                   "Host unreachable",
61                   "Connection refused",
62                   "TTL expired",
63                   "Command not supported",
64                   "Address type not supported" };
65
66    static final String JavaDoc localErrorMessage[] ={
67                   "SOCKS server not specified",
68                   "Unable to contact SOCKS server",
69                   "IO error",
70                   "None of Authentication methods are supported",
71                   "Authentication failed",
72                   "General SOCKS fault" };
73
74    String JavaDoc errString;
75    int errCode;
76
77 }//End of SocksException class
78

79
Popular Tags