I used alert method in the below code”
    try {
        Alert alert = webDriver.switchTo().alert();
         alert.getText();
                     log().info("Alert detected: {}" + alert.getText());
        alert.accept();
    } catch (Exception e) {
    }
When there is no alert on the current state, it waits for a specific amount of time until the timeout is reached, then throws an exception.How to do it in better way?