Is anyone here using Kovenant for background tasks...
# android
m
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
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
No, there is failUI callback, but that checks if the exception was thrown inside the task{}-scope, not in the successUi{}-scope
l
OK, so would you then need the try/catch both inside the
successUI
scope?
m
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} …