Question: I am using the `tensorflow` `object detection api` on windows system and it has been working fine. I am using the pre-trained model as of now which is `ssd_mobilenet_v1_coco_11_06_2017`. It is easily detecting all the objects in a given input video. I wanted to record time of each object so lets say, if in a video a car enters at `00:05` and leaves at `00:15` which means that it was in for `10secs`. 

To achieve this, I was looking if there is anything like id of each detected object which the API returns so that I can start a timer from the code to calculate the time of an object. Is there any already built functionality for this in the API.?

Answer: 
That is because `doException` is throwing exception inline. If you want to use `Either`, you have to *return* `Future(Left(exception))` rather than throwing it. 

I think, you are kinda overthinking this. It does not look like you need `Either` here ... or `cats` for that matter. 

Why not do something simple, like this:

```
 class ExternalService {
   def doAction(): Future[Int] = Future.successful(2)

   def doException(): AsyncResult[Int] = {
     println("do exception")
     Future.failed(NullPointerException("run time exception")) 
     // alternatively: Future { throw new NullPointerExceptioN() }
 }

 class ExceptionExample {
   private val service = new ExternalService()

   def callService(): AsyncResult[Int] = {
     println("start callService")
       val result = for {
         num <- service.doException()
     } yield num
     // Note: the aboive is equivalent to just
     // val result = service.doException
     // You can write it as a chain without even needing a variable:
     // service.doException.recover { ... }

     result.recover { case ex: Throwable =>
       println("recovered exception")
       Future.successful(99)
    }
 }

```
I tend to agree that it seems a bit convoluted, but for the sake of the exercise, I believe there are a couple of things that don't quite click.

The first one is the fact that you are throwing the Exception instead of capturing it as part of the semantics of Future. ie. You should change your method `doException` from:

```
def doException(): AsyncResult[Int] = {
    println("do exception")
    throw new NullPointerException("run time exception")
}

```

To:

```
def doException(): AsyncResult[Int] = {
    println("do exception")
    AsyncResult(Future.failed(new NullPointerException("run time exception")))
}

```

The second bit that is not quite right, would be the recovery of the Exception. When you call `recoverWith` on an `EitherT`, you're defining a partial function from the `Left` of the `EitherT` to another `EitherT`. In your case, that'd be:

`ServiceError => AsyncResult[Int]`

If what you want is to recover the failed future, I think you'll need to explicitly recover on it. Something like:

```
AsyncResult {
  result.value.recover {
    case _: Throwable => {
      println("recovered exception")
      Right(99)
    }
  }
}

```

If you really want to use `recoverWith`, then you could write this instead:

```
 AsyncResult {
    result.value.recoverWith {
      case _: Throwable =>
        println("recovered exception")
        Future.successful(Right(99))
    }
  }

```