Q:

replace try catch into Try in scala

 private def getDeviceDataByDeviceId(validId: String): Future[List[MonitoringData]] = {
    try {
      temperatureProcessorReadDAO.getTemperatureByDeviceId(validId).flatMap {
        case Nil => throw TemperatureNotFoundException(TransportErrorCode.NotFound,
          Error.DeviceErrorMessageForDataNotFound + validId)
        case listOfMonitoringData => Future(listOfMonitoringData)
      }

    } catch {
      case exception: Throwable => throw new Exception(exception.getMessage)
    }

I have to change this particular code of scala and replace try catch into Try 
this is what I have done but it is not correct
private def getDeviceDataByTimeInterval(validStartTime: String, validEndTime: String): Future[List[MonitoringData]] = {
    Try(temperatureProcessorReadDAO.getTemperatureByTimeInterval(validStartTime, validEndTime)) match {
      case Success(List()) => throw TemperatureNotFoundException(TransportErrorCode.NotFound,
        Error.TimeIntervalErrorMessageForDataNotFound + validStartTime + validEndTime)
      case Success(listOfMonitoringData) => listOfMonitoringData
      case Failure(exception) => throw new Exception(exception.getMessage)
    }
  }

can you tell me what can be correct answer 

A:

I don't think you need any try or Try there at all: it looks like .getTemperatureByDeviceId returns a Future, so it should not be throwing anything inline, and just return a failed Future if exception happens.
If it does throw inline, your best option is to fix it (it is a really bad idea to throw in a function that is supposed to return Future), or, if you can't for some reason, just put it inside a flatMap:
 Future
   .successful(validId)
   .flatMap(temperatureProcessorReadDAO.getTemperatureByDeviceId)
   .map {
     case Nil => throw TemperatureNotFoundException(...)
     case result => result
   }

As a side note, never catch Throwable, use case NotFatal(exception) => ... instead. In any case, your catch clause seems pretty pointless: you catch everything, throw away any useful information, like type or stack trace from the original exception, and then just throw a generic Exception with only the original message. Don't do that.

