Hopefully this is fairly basic. I've never used enumerated types in Java. I'm sort of trying to take my C concept of them and make it work in Java. Basically use them as constant integer values. That might be putting the square C block into the round Java hole. I'm not sure. Here's the code. It's giving me errors in lines 42 and 47 (inconvertible types). If the constructor gets passed 3, I want this.code
to be assigned to be INVALID_BYTE_VALUE.
package PacketException;
public class PacketException
{
public static enum ExceptionCode
{
UNSPECIFIED_PACKET_EXCEPTION,
INVALID_HEX_DIGIT,
INVALID_BINARY_DIGIT,
INVALID_BYTE_VALUE,
INVALID_HEX_BYTE_TEXT_REP,
INVALID_BINARY_BYTE_TEXT_REP,
INVALID_PACKET_TEXT_REP,
INVALID_EVAL_BOARD_SNIFFER_PARSE,
INVALID_ENCODED_BYTE,
INVALID_DECODED_BYTE,
INVALID_CRC,
INVALID_PACKET_LENGTH,
INVALID_ENCRYPTION_METHOD,
INVALID_PTYP,
INVALID_PREAMBLE,
INVALID_SOF,
INVALID_HOPS,
INVALID_NACK_REASON,
INVALID_DATA_RATE
}
public String message;
public ExceptionCode code;
public PacketException ()
{
this.code = ExceptionCode.UNSPECIFIED_PACKET_EXCEPTION;
this.message = "";
}
public PacketException (int code)
{
this.code = (ExceptionCode) code;
}
public PacketException (String message, int code)
{
this.code = (ExceptionCode) code;
this.message = message;
}
}