title: Returning String from a do-catch statement
body: <p>I was trying to translate the code from swift 2 to swift 4 and came across this error </p>
  
  <blockquote>
    <p>Errors thrown from here are not handled</p>
  </blockquote>
  
  <p>So I did this but now it tells me to return a string. Any idea how to do this?    </p>
  
  <pre><code>func formatSentence(sentence:String) -&gt; String
  {
      do {
          let regex = try NSRegularExpression(pattern: "\\W+", options: .caseInsensitive)
          let modifiedString = regex.stringByReplacingMatches(in: sentence, options: [], range: NSRange(location: 0,length: sentence.count), withTemplate: "")
  
      } catch {
          print(error)
      }
  
      //I tried adding it here the return modifiedString but gives me error
  }
  </code></pre>
  
  <p>This is what the original function looks like</p>
  
  <pre><code>func formatSentence(sentence:String) -&gt; String
  {
      let regex = NSRegularExpression(pattern: "\\W+", options: .caseInsensitive)//NSRegularExpression(pattern:"\\W+", options: .CaseInsensitive, error: nil)
      let modifiedString = regex.stringByReplacingMatches(in: sentence, options: [], range: NSRange(location: 0,length: sentence.count), withTemplate: "")
  
      return modifiedString
  }
  </code></pre>