Implemented catching and logging exceptions

This commit is contained in:
dankito 2020-11-12 23:50:05 +01:00
parent f88070181d
commit 1b6e5c363b
1 changed files with 14 additions and 2 deletions

View File

@ -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<Image>(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
}
}