title: how to use akka.actor.Status.Failure to catch the exception
body: <p>I have an actor which is responsible for MongoDB CRUD operations it may throw a <code>mongoException</code> i want to caught this exception in the calling code where i am using the ask pattern but i am still getting a TimeOutException which is not required in my case from the docs i have gone <a href="https://doc.akka.io/docs/akka/current/actors.html#receive-timeout" rel="nofollow noreferrer">over this link</a> </p>
  
  <blockquote>
    <p>Warning
    To complete the with an exception you need to send an akka.actor.Status.Failure message to the sender. This is not done automatically when an actor throws an exception while processing a message.</p>
  </blockquote>
  
  <p>I followed the code snippet given in the docs </p>
  
  <p>here is my code </p>
  
  <pre><code>class test extends Actor {
  
  def receive () {
  
  case GetRecordLists=&gt;
  try {  
   //some operations here 
     sender ! resultList
  }
  catch {
    mongoEX:MongoException=&gt;
    log.error("got mongodb exception",mongoex)
    sender ! akka.actor.Status.Failure(mongoEx)
    throw mongoEx
  
  e:Exception=&gt;
    log.error("got exception",e)
    sender ! akka.actor.Status.Failure(e)
    throw e
  }
  
  }
  
  }
  
  
  class MainClass extends App {
  
  try {
       val future: Future[scala.collection.mutable.Set[String]] = ask(test, GetRecordLists).mapTo[scala.collection.mutable.Set[String]]
       val results = Await.result(future, timeout.duration)
      }
      catch  {
        case e:Exception=&gt;log.error("got the exception in main class ",e)
        throw new Exception(e)
      }
  }
  </code></pre>
  
  <p>here the expected behavior is to caught the <code>MongoException</code>
  but i am getting </p>
  
  <pre><code>java.util.concurrent.TimeoutException: Futures timed out after [5 seconds]
      at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:219) ~[scala-library-2.11.1.jar:na]
      at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:223) ~[scala-library-2.11.1.jar:na]
      at scala.concurrent.Await$$anonfun$result$1.apply(package.scala:111) ~[scala-library-2.11.1.jar:na]
      at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:53) ~[scala-library-2.11.1.jar:na]
      at scala.concurrent.Await$.result(package.scala:111) ~[scala-library-2.11.1.jar:na]
      at MainClass(MainClass.scala:118) [xyz_2.11.jar:0.1.0-SNAPSHOT]
  </code></pre>