Skip to content

Instantly share code, notes, and snippets.

@abdurahmanadilovic
Created December 17, 2017 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdurahmanadilovic/3e54fe33584498b68fbba2c17ad5e322 to your computer and use it in GitHub Desktop.
Save abdurahmanadilovic/3e54fe33584498b68fbba2c17ad5e322 to your computer and use it in GitHub Desktop.
Exception handling with launch coroutine and exception handler
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