'Kafka Scala: How to move val into try catch block

I'd like to move:

val kafkaPartitionOffset = kafkaConsumer.endOffsets(consumedPartitions.asJava)

into a try catch block like so:

val kafkaPartitionOffset : SomeClass = 
            try {
               kafkaConsumer.endOffsets(consumedPartitions.asJava)
            } catch {
              case e: Exception => {
                log.error(s"${consumerGroupId} Could not get Kafka offset", e)
                None
              }
            }

But I'm having trouble on what the SomeClass should be. I've tried Map[TopicPartition, Long] but it says Type mismatch. Any help is appreciated, thank you!

Update: I've also tried Any but I'm unable to do a kafkaPartitionOffset.get(topicPartition) below (get is highlighted red with error message cannot resolve symbol get:

        for((topicPartition,OffsetAndMetadata) <- mapTopicPartitionOffset){
          
          val bbCurrentOffset =  OffsetAndMetadata.get(topicPartition)

          // latest offset
          val partitionLatestOffset = kafkaPartitionOffset.get(topicPartition)

          // Log for a particular partition
          val delta = partitionLatestOffset - bbCurrentOffset

          topicOffsetList += delta.abs

        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source