Created
December 17, 2017 20:46
-
-
Save abdurahmanadilovic/3e54fe33584498b68fbba2c17ad5e322 to your computer and use it in GitHub Desktop.
Exception handling with launch coroutine and exception handler
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
private val exceptionHandler: CoroutineContext = CoroutineExceptionHandler { _, throwable -> | |
alertWithOkButton("Exception caught inside the exception handler") | |
throwable.printStackTrace() | |
} | |
private fun getAllUsers() { | |
launch(parentJob + UI + exceptionHandler) { | |
val listOfUsers = run(CommonPool) { | |
RestClient.apiDefinition.listUsers().execute() | |
} | |
val numberOfUsers = "number of users ${listOfUsers.body()?.size}" | |
numberOfUsersTextView.text = numberOfUsers | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment