How does Selenium handle no such window Exception?

How can I handle the no such window Exception in Selenium?

NoSuchWindowException WebDriver Exception occurs when the driver. switchTo().window(“XYZ”) in the Selenium script is not able to locate the pop-up window on the web page.

To handle NoSuchWindowException in Selenium, you can use NoSuchWindowException WebDriver Class in the catch block.

Read more about this exception here.