ESCPOS-ThermalPrinter-Android icon indicating copy to clipboard operation
ESCPOS-ThermalPrinter-Android copied to clipboard

catch errors

Open mcapello opened this issue 6 years ago • 1 comments

Hi, thanks for your job !

How is the best way to catch errors when you do this ?

EscPosPrinter printer = new EscPosPrinter(BluetoothPrintersConnections.selectFirstPaired(), 203, 48f, 32);

mcapello avatar Jun 20 '20 17:06 mcapello

DeviceConnection printerConnection = BluetoothPrintersConnections.selectFirstPaired();
if(printerConnection == null) {
    // No printer is connected...
} else {
    try {
        EscPosPrinter printer = new EscPosPrinter(printerConnection, 203, 48f, 32);
    } catch (EscPosConnectionException e) {
        // Printer is disconnected...
        e.printStackTrace();
    }
}

DantSu avatar Jun 22 '20 10:06 DantSu