Apologies if this question is super-obvious. I’m not from a Java background so a lot of this is foreign to me.
I have a project I’m working on that uses the “org.jetbrains.exposed.sql” module to interact with an sqlite database. Everything about the module works fine, except… the project dies if the database isn’t found. This should be a possible option, since the database is held on a network drive, and the connectivity may be poor. I’m tearing my hair out trying to figure out how to handle that scenario in Kotlin. I’ve googled every youtube video and tutorial on exception handling and I’m 1000% clear on how to handle an exception in the abstract, but this simply NEVER works when running the command to connect to the database. (it absolutely DOES work when attempting other processes that could fail, like the often-tutorialed divide-by-zero)
Database.connect("jdbc:sqlite:$ databaseName ", “org.sqlite.JDBC”)
This should return false if there was an exception and true if the database connected, however if the database is not found, the program completely crashes rather than handling and returning false.
[main] WARN Exposed - Transaction attempt #0 failed: path to ‘badpath’: ‘\’ does not exist. Statement(s): null
java.sql.SQLException: path to ‘badpath’: ‘\’ does not exist
Process finished with exit code 1
As you can see, the exception IS an SQLException (although it makes my brain hurt that you have to guess all of the exact types of exceptions your code might ever theoretically have for the try-catch to be able to handle it)
So… What am I doing wrong here? Is there a more robust way to tell Kotlin to try something and just let me know if it failed instead of committing ritual suicide?