title: How to return None in Scala
body: <p>For my first Scala program, I am trying to write a small utility which will convert an XML file from one schema to another. </p>
  
  <p>I started writing a method which will give me the file contents: </p>
  
  <pre><code>  def loadFile(filename: String, encoding: String = "utf-8"):Option[String] = {
      try
      {
        val source = scala.io.Source.fromFile(filename, encoding)
        val contents = source.mkString
        source.close()
        return Some(contents)
      }
      catch 
      {
        return None
      }
  
    }
  </code></pre>
  
  <p>But it does not compile. I get back "value apply is not a member of Nothing" and "value isDefinedAt is not a member of Nothing" as error messages from the line <code>return None</code>. </p>
  
  <p>All the examples I can find returning an Option use matching, but this does not make sense here. I just want to not fail if I can't read the file for some reason. </p>
  
  <p>What should I do in this case? Is there a pattern for doing this kind of thing in Scala? </p>