Connect to the Printer

The LabelPrinter and LinePrinter classes inherit the connect method from the parent class, Printer. The application must call the connect method to connect to the printer before invoking other methods to interact with the printer; otherwise, an exception is thrown. The connect method uses the aPrinterUI parameter specified in the constructor to determine the printer to be connected and the communication method used.

public void connect() throws PrinterException

If you call the connect method from a LinePrinter object and an unexpected error occurs, it throws LinePrinterException which is a subclass of PrinterException. Likewise, calling the connect method from a LabelPrinter object throws LabelPrinterException which is also a subclass of PrinterException. You may use PrinterException to catch either LinePrinterException or LabelPrinterException.