https://kotlinlang.org logo
Title
k

Kevin

02/09/2019, 1:09 AM
I want to validate a filepath to a sqlite database and provide helpful feedback, is this an appropriate way to accomplish this?
return when {
    filename.isNullOrBlank() -> context.error("Cannot be blank")
    !File(filename).exists() -> context.error("File does not exist")
    !File(filename).isFile -> context.error("Not a file")
    !File(filename).canRead() -> context.error("Permission Denied")
    else -> when (val code = canConnect(filename)) {
        SQLiteErrorCode.SQLITE_OK -> context.success()
        else -> context.error(code.message)
    }
}
I only want to try to open a JDBC connection once I know it’s a valid filepath and all that, but is nesting a
when
inside the
else
of another
when
bad form?
k

karelpeeters

02/10/2019, 11:30 AM
I wouldn't consider nesting `when`s bad form.