Last active
December 17, 2017 20:43
-
-
Save abdurahmanadilovic/21f9d909751d2c7359135dbe575773b4 to your computer and use it in GitHub Desktop.
Exception handling with kotlin launch coroutine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun sendCreateUserRequest(firstName: String, lastName: String) { | |
launch(parentJob + UI) { | |
try { | |
val listOfUsers = run(CommonPool) { | |
val user = User(firstName, lastName) | |
RestClient.apiDefinition.createUser(user).execute() | |
} | |
toast("Created user id is ${listOfUsers.body()?.id}") | |
} catch (ex: IOException) { | |
alertWithOkButton("Error with internet connection") | |
} catch (ex: RuntimeException) { | |
alertWithOkButton("Error with parsing server response") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment