104
Exception handling
A command transmission/reception API generates a propriety exception with an integer (int) type
parameter when an error occurs and notify the calling side of such an error.
Steps for Handling
Use the EpsonIoException class's getStatus (p.99) to get the error value. Please refer to the following code.
List of Error Values
Error values are defined in the IoStatus class.
Error Value Cause
IoStatus.ERR_PARAM
Invalid parameter was passed.
<Example>
An invalid parameter such as null was passed.
A value outside the supported range was specified.
IoStatus.ERR_OPEN Open processing failed.
IoStatus.ERR_CONNECT
Failed to connect to device.
<Example>
Failed to send data to the target device for a reason other than
a timeout.
Failed to receive data from the target device for a reason other
than a timeout.
IoStatus.ERR_MEMORY Could not allocate the necessary memory for processing.
IoStatus.ERR_ILLEGAL
Illegal method used.
<Example>
The API for sending and receiving data was called when the
device port was not open.
The printer search API was called again when a printer search
was already in progress.
IoStatus.ERR_PROCESSING
Could not execute process.
<Example>
Could not get lock rights to the shared resource because the
same process is currently being executed by another thread.
IoStatus.ERR_FAILURE An unspecified error occurred.
String str = "Hello, World!\r\n";
byte[] data = str.getBytes();
int offset = 0;
int size = data.length;
int timeout = 5000;
int sizeWritten = 0;
int errStatus = IoStatus.SUCCESS;
try {
sizeWritten = mPort.write(data, offset, size, timeout);
} catch ( EpsonIoException e ) {
//Get error value
errStatus = e.getStatus();
}