Exceptions

Printer methods throw a PrinterException. You may use PrinterException to catch either LinePrinterException or LabelPrinterException.

For backwards compatibility, you may continue to use LinePrinterException to catch exceptions from LinePrinter methods, including those exceptions inherited from Printer. Similarly, you may use LabelPrinterException to catch exceptions from LabelPrinter methods, including those exceptions inherited from Printer.

These are the exception class definitions:

public class PrinterException extends Exception
public class LinePrinterException extends PrinterException
public class LabelPrinterException extends PrinterException

The PrinterException class inherits the getMessage method from the Exception class. The getMessage method returns a detailed message of the exception.

It also has a getErrorCode method that returns an error code associated with this exception.

public int getErrorCode()

The PrinterException class defines the following error code constants that applications may examine to make logical decisions. All other error code values are for error reporting and debugging purposes only.

public static final int ERROR_ALREADY_CONNECTED
public static final int ERROR_FILE_NOT_FOUND
public static final int ERROR_INVALID_NET_ADDRESS
public static final int ERROR_INVALID_PRINTER_ID
public static final int ERROR_NO_CONNECTION
public static final int ERROR_FILE_INVALID