I have the code bellow: ``` suspend fun doSomethi...
# coroutines
p
I have the code bellow:
Copy code
suspend fun doSomethingAndThrow() { throw(MyException()) }

val coroutineScope = CoroutineScope(Job())

coroutineScope.launch {
  
  try { doSomethingAndThrow() } catch(exception: Exception) { Log.d("MyException got caught")  }

}
Is the exception thrown in the suspended fun doSomethingAndThrow(…) caught by my try/catch block or it gets caught through the CoroutineScope hierarchy. What would be a good practice to catch this exception?
l
This code doesn't compile. After you fix it, you'll receive
MyException
in the
catch
block, as it would do with non suspending code.
👍 1
p
Sorry about that I just type it out of my head. Is more a pseudo code than actual Kotlin code. Thanks for responding.
s
Maybe this will help you: “Exceptional Exceptions for Coroutines made easy…?” by Anton Spaans https://link.medium.com/rQ01l9CdWY
p
Thanks man, I LL take a look when I got home.
@streetsofboston That medium article is gold man!
👍 1