0

I don't think I can get an answer in the suggested duplication. I hope someone can answer

I have the following code:

    private void VerifyLegMessages(long lCurrentTimeMs){

    m_arrLegs.forEach((x) -> {

            if(x.getReqSentMs() != -1){

                if(x.getOkReceivedMs() ==  -1){

                    if(lCurrentTimeMs - x.getReqSentMs() > MAX_TIMEOUT_MS){
                        throw new TimeoutException("Did not receive message on time. Timeout has passed... ");
                    }
                }else{

                    if(x.getOkReceivedMs() - x.getReqSentMs() > MAX_TIMEOUT_MS){
                        throw new TimeoutException("response time was longer than expected... ");
                    }               
                }
            }
        }
    );
}

Eclipse yells at me because of the "throw new TimeoutException" and wants me to put the code inside a try and catch block.

Why can't I throw the exception as I could do on other similar methods, where I haven't been using lambda expressions?

Thank you!

dushkin
  • 1,939
  • 3
  • 37
  • 82

0 Answers0