title: Scala: who can explain this?
body: <p>Consider the following Scala code:</p>
  
  <pre><code>case class Data[T](value: Option[T]) {
    def get: T = try {
      doGet
    } catch {
      case e: Exception =&gt; throw new IllegalArgumentException
    }
  
    def doGet: T = value match {
      case Some(v) =&gt; v
      case None =&gt; ().asInstanceOf[T]
    }
  }
  
  Data[Unit](None).get
  Data[Integer](None).get // which exception is thrown here?
  </code></pre>
  
  <p>[spoiler] It is a <code>ClassCastException</code>; who can explain why it is not caught and replaced by an <code>IllegalArgumentException</code>?</p>
  
  <p>PS: To preempt any questions on why I would want to do this: this is a simplified version of some code that uses json4s to parse some string into an <code>Option[T]</code>; if the parsing fails <code>None</code> is returned, which is OK if <code>T</code> was <code>Unit</code> and not OK if <code>T</code> is some other type.</p>