https://kotlinlang.org logo
#exposed
Title
# exposed
j

JP

10/09/2020, 8:18 PM
Does anyone know how to return a value from a transaction while having a try/catch to handle errors? I posted about in this issue here, because the only way I've found to work around this is by having a separate variable and assigning to that, which is pretty gross.
Copy code
var a = -1
newSuspendedTransaction {
    try {
        a = Users.insert {
            it[username] = model.username
        } get Users.userId
    } catch (e: Exception){

    }
}

return a
Any ideas as to how I can return the value from the transaction while also handling error? I've tried handling the error outside the transaction, but for some reason, transactions don't let errors bubble up
t

tapac

10/13/2020, 8:47 AM
Did you try to commit transaction before end of
try
block like adviced here?
3 Views