[Coroutine] Exception handling in coroutine # coroutine builder 에 exception 이 발생하면 parent 를 cancel 하고, parent 가 cancel 되면 모든 children 을 cancel 시킨다. (exception propagation) Stop breaking my coroutines # Exception propagation 은 job 을 기반으로 작동하기 때문에 try-catch 로 잡히지 않는다. SupervisorJob # SupervisorJob 은 한 child 의 exception 이 parent 와 다른 children 을 cancel 시키지 않는다. # 일반적인 실수는 parent coroutine 에 SupervisorJob 을 전달하는 것이다. 예를 들면 launch 에 SupervisorJ.. 2022. 1. 30. [coroutine] Exception handling Exception propagation - Coroutine builder 는 2가지 flavor 가 있다. exception 을 자동으로 전파하는 launch, actor류. 그리고 user 에게 노출되는 async, produce 류. 자동 전파하는 케이스는 Java 의 uncaughtExceptionHandler 와 비슷하게 unhandled exception 이다. 반면에 user 에게 노출되는 경우는 user 가 exception 을 직접 handle 할 수 있다. (돼왕: try-catch 할 수 있다.) 대표적 api 는 await 와 receive 가 있다. - runBlocking{ val job = GlobalScope.launch{ println(“Throwing exception f.. 2019. 3. 4. 반응형 이전 1 다음