Error even after throws Exception for thread.sleep

Denise :

I am trying to make my Thread sleep and am making the method throws InterruptedException, however it is still giving the error "Unhandled exception"


  @Before
    public void setUp() throws InterruptedException{

        simulatorList.forEach(simulation -> {
           ....
            Thread.sleep(1000*60*1);
//giving error here 

            ...
        });
}
ahmad adawi :

Because you calling Thread.sleep inside foreach, Below will solve your issue:

public void setUp() throws InterruptedException {
    List<String> simulatorList = new ArrayList<>();
    for (String s : simulatorList) {
        Thread.sleep(1000 * 60 * 1);
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=23269&siteId=1