title: Understanding catch in Scala
body: <p>I wrote the following simple example:</p>
  
  <pre><code>def main(args: Array[String]) = {
      try{
        throw new IllegalArgumentException
      } catch {
        case Ex(e) =&gt; println("IllegalArgumentException was thrown")
      }
  }
  
  object Ex{
    def unapply(arg: Throwable): Option[Throwable] = arg match {
      case arg: IllegalArgumentException =&gt; Some(arg)
      case _ =&gt; None
    }
  }
  </code></pre>
  
  <p>and was pretty confused by that it's working. In the catch clause we didn't even declare <code>e</code>. And another was that in the catch clause we match against <code>Some[Throwable]</code>, not the <code>Throwable</code> itself. So, I tried to do the following:</p>
  
  <pre><code>catch {
        case Ex(e) =&gt; println("IllegalArgumentException was thrown")
        case None =&gt; println("None")  //error, found None.type required Throwable
      }
  </code></pre>
  
  <p>and it didn't work. Why? We matched against <code>Some[Throwable]</code>. What's wrong with <code>None</code>?</p>