https://kotlinlang.org logo
#android
Title
# android
m

Markus

05/17/2019, 12:57 PM
Is anyone here using Kovenant for background tasks? I don’t understand how to catch exceptions thrown in the lambda try { task { doSomething() } successUI { throw Exception() } } catch (e:Exception) {} // This will not catch anything
l

luke

05/17/2019, 12:59 PM
I don’t use it, but is there something that can be caught like:
Copy code
task {
   doSomething()
 } successUI {
 throw Exception()
 }.exception {
// handle here
}
m

Markus

05/17/2019, 1:01 PM
No, there is failUI callback, but that checks if the exception was thrown inside the task{}-scope, not in the successUi{}-scope
l

luke

05/17/2019, 1:02 PM
OK, so would you then need the try/catch both inside the
successUI
scope?
m

Markus

05/17/2019, 1:03 PM
yes, but I need to break out of the scope as well if there is an exception so the code that is after the code that generated the exception does not execute.. not sure how to do that. return does not work
basically in this successUI {} I get some token-data from network which is validated before i throw a new task{} that uses the token. If there is a validation error the next task should not execute
so if using an inner try/catch i would want something like try { validateToken() } catch(e:Exception) { showErrorUi() return // this is not allowed here } task { do exciting things} …
3 Views