title: using a partial function for catch block with scala
body: <p>I have a catch block that I end up repeating quite a bit, and found this SO question that confirmed that I can use a partial function as a catch block (What are the use cases for Scala 2.9's try…catch generalization?  <a href="https://stackoverflow.com/questions/7788803/what-are-the-use-cases-for-scala-2-9s-try-catch-generalization">1</a>).  </p>
  
  <p>Currently, my code looks like this:</p>
  
  <pre><code>var task = newTask("update product", "update for customer " + customerId.toString)
  try {
            val vcdRouter = actorSystem.actorFor("user/supervisor/router-10.10.10.10:443")
  
            val vdcId = new UUID("92ddba5e-8101-4580-b9a5-e3ee6ea5718f")
            val vdcGet = sendExpect[AdminVdcType](vcdRouter, GetVdc(vdcId))
            val vdcPut = VdcPutConfig(vdcGet, c)
            val vdcPutTask = sendExpect[TaskType](vcdRouter, UpdateVdc(vdcId, vdcPut))
  
            task = task.copy(Progress = 100, status = SuccessType)
  
          } catch {
            case failure: NoResponseBodyException =&gt;
              logger.debug("*** In putCustomerProduct, got a Left(VcdGatewayException)")
              task = task.copy(Progress = 100, status = Error, Error = Option(exceptionToError(failure, BadGateway)))
  
            case failure: VcdGatewayException ⇒
              logger.debug("*** In putCustomerProduct, got a Left(VcdGatewayException)")
              task = task.copy(Progress = 100, status = Error, Error = Option(exceptionToError(failure, GatewayTimeout)))
  
            case failure: Exception ⇒
              logger.debug("*** In putCustomerProduct, got a Left(Exception)")
              task = task.copy(Progress = 100, status = Error, Error = Option(exceptionToError(failure)))
  
          }
  </code></pre>
  
  <p>Since I have this task var that is changing inside the catch block, is there a nice way to make it accessible from within a partial function that holds the catch block?  The task is a var since it sets some initialization data like a created timestamp upon entry into the system.  I could work around this, but am interested in an answer to the original question anyway.</p>