Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to use coroutine scope to call web service and handle error kotlin

 
Ranch Hand
Posts: 179
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I develop an android app with Kotlin, api 28. I also use swaggerHub and swagger.json to get all WS. In swaggerHub, I export the client sdk Kotlin.After export the "Kotlin_client_generated" file with swagger, and add it in my project.
Here is an example of ws code, among others ws :

After a while of research, about How to consume this WS, I found that I should use coroutine and I use a GlobalScope with Dispatchers :

I want to handle the exception with try/catch and dispaly the error in a Toast,How can I do that.
I found that I should use Coroutine Scope instead of Global Scope and the Global Scope is highly disouraged.
So,How to use coroutine scope to call web service and handle error ?
Could you please help me to solve my problem
 
Maha Sakka
Ranch Hand
Posts: 179
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I try to change it to the following :
 
But, Still don't work
 
Maha Sakka
Ranch Hand
Posts: 179
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found the solution, I use CoroutineExceptionHandler :
 
Master Rancher
Posts: 640
10
Android Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maha Sakka wrote:I found the solution, I use CoroutineExceptionHandler :


Well done!
 
reply
    Bookmark Topic Watch Topic
  • New Topic