title: Is NetworkOnMainThreadException valid for a network call in a coroutine?
body: <p>I'm putting together a simple demo app in Kotlin for Android that retrieves the title of a webpage with Jsoup. I'm conducting the network call using <code>Dispatchers.Main</code> as context. </p>
  
  <p>My understanding of coroutines is that if I call <code>launch</code> on the <code>Dispatchers.Main</code> it <em>does</em> run on the main thread, but suspends the execution so as to not block the thread.</p>
  
  <p>My understanding of <code>android.os.NetworkOnMainThreadException</code> is that it exists because network operations are heavy and when run on the main thread will block it.</p>
  
  <p>So my question is, given that a coroutine does not block the thread it is run in, is a <code>NetworkOnMainThreadException</code> really valid? Here is some sample code that throws the given Exception at <code>Jsoup.connect(url).get()</code>:</p>
  
  <pre><code>class MainActivity : AppCompatActivity() {
      val job = Job()
  
      val mainScope = CoroutineScope(Dispatchers.Main + job)
  
      // called from onCreate()
      private fun printTitle() {
          mainScope.launch {
              val url ="https://kotlinlang.org"
              val document = Jsoup.connect(url).get()
              Log.d("MainActivity", document.title())
              // ... update UI with title
          }
      }
  }
  </code></pre>
  
  <p>I know I can simply run this using the <code>Dispatchers.IO</code> context and providing this result to the main/UI thread, but that seems to dodge some of the utility of coroutines.</p>
  
  <p>For reference, I'm using Kotlin 1.3.</p>