Challenge: Cancellation of a Job
Explore how to implement cancellation of a job in Kotlin coroutines by using try-catch blocks to catch CancellationException. Understand how to use coroutine builders and job functions to cancel coroutines properly while controlling output in terminal applications.
Problem
When a job is canceled, it changes its state to “Cancelling.” Then, at the first suspension point, a CancellationException is thrown. Write a code that will catch this exception using try and catch and use the job ...