```class RequestContextTest : StringSpec({ "pl...
# coroutines
s
Copy code
class RequestContextTest : StringSpec({
    "playing with human context" {

        runBlocking {

            supervisorScope {


                try {
                    val repoSize = async<String> {
                        // do remote
                        val somenestedOp = async<String> {
                            delay(100)
                            throw DomainException("oh no", Exception("400"))
                        }
                        somenestedOp.await()
                    }

                    repoSize.await()
                } catch (de: DomainException) {
                    println("we will swallow")

                }


            }


        }
        println("we exited okay")
    }


})

class DomainException(msg: String, t: Throwable) : Exception(msg, t)
l
Let’s say on this block I have to catch the exception and then throw the domain, would be fine just to catch, map and rethrow?
Copy code
val somenestedOp = async<String> {
                            delay(100)
                            throw DomainException("oh no", Exception("400"))
                        }
s
can you mock up an example? but if i think you're asking what you are then yes
l
using your exemple, something on this line
Copy code
val somenestedOp = async<String> {
    try{
        someOperation()
    }catch (de: DataException){
        val  mappedException = when(de){
            is HttpException -> throw DomainException("oh no", Exception("400"))
            is IOException -> throw OtherDomainException("oh no", Exception("300"))
        }
        throw mappedException()
    }
}
s
yes that should work (presuming someOperation is not a special coroutinebuilder). the supervisor scope limits the propagation of cancellation upstream, presuming you handle the exception
l
Oh thanks then đŸ˜„
s
you can see how supervisorScope changes the behavior by swapping it coroutineScope and back, i.e. the exception despite being handled on await() still propagates up the chain
l
Yeah I just finished the test here using the
runCatching{}.recover{}
and it worked beautifully I was just wondering if it was a common thing rethrowing errors, I was used to Rx way of composing the upstream with transformers + onErrorResumeNext
s
I'm not familiar with the Rx way so not sure, there is an #rx channel incase youve not seen that though
l
No problem at all