title: How to cancel (return from) a Kotlin coroutine from within the scope immediately?
body: <p>In the following code I want to stop the execution of this scope when an exception was caught.</p>
  
  <pre><code>GlobalScope.launch() {
     try {
         someFunctionThatThrows()
     } catch (exception: Exception) {
         // log
         cancel() // this is not stopping the coroutine and moreWork() is still executed
     }
     moreWork()
  }
  </code></pre>
  
  <p><code>cancel()</code> does not cancel the coroutine immediately but instead sets the flag <code>isActive</code> to false, which requires subsequent checking. </p>