Hi Kabir, this type of error occurs when WebDriver tries to switch to an invalid window or to a window which doesn't exists. You can use try and catch to catch the exception in the following way:
for (String handle : driver.getWindowHandles()) {
try {
driver.switchTo().window(handle);
} catch (NoSuchWindowException e) {
System.out.println(“An exceptional case”);
}
}