From 1b6e5c363b8c6e1762c60d119e7d29af16712a14 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 12 Nov 2020 23:50:05 +0100 Subject: [PATCH] Implemented catching and logging exceptions --- .../banking/epcqrcode/windows/main/MainWindow.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/windows/main/MainWindow.kt b/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/windows/main/MainWindow.kt index f7369c2..bb5a522 100644 --- a/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/windows/main/MainWindow.kt +++ b/EpcQrCodeJavaFxApp/src/main/kotlin/net/codinux/banking/epcqrcode/windows/main/MainWindow.kt @@ -6,10 +6,16 @@ import tornadofx.* import java.io.ByteArrayInputStream import net.codinux.banking.epcqrcode.MppTest import net.codinux.banking.epcqrcode.QrCodeGenerator +import org.slf4j.LoggerFactory class MainWindow : View(FX.messages["application.title"]) { + companion object { + private val logger = LoggerFactory.getLogger(MainWindow::class.java) + } + + private val qrCodeGenerator = QrCodeGenerator() private val qrCode = SimpleObjectProperty(generateQrCode(MppTest().getTestEpcQrCodeContent())) @@ -21,9 +27,15 @@ class MainWindow : View(FX.messages["application.title"]) { private fun generateQrCode(informationToEncode: String): Image? { - val qrCodeBytes = qrCodeGenerator.generateQrCode(informationToEncode) + try { + val qrCodeBytes = qrCodeGenerator.generateQrCode(informationToEncode) - return Image(ByteArrayInputStream(qrCodeBytes)) + return Image(ByteArrayInputStream(qrCodeBytes)) + } catch (e: Exception) { + logger.error("Could not generate QR code for $informationToEncode", e) + } + + return null } } \ No newline at end of file