'How to make Selenium to ignore failed proxies?

I am trying to test some proxies on www.google.com but Selenium gets stopped at not working proxies without scanning remaining proxies:

package hello1;

import java.time.Duration;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;


public class Hello1 {


    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.chrome.driver","D:\\ChromeDriver\\chromedriver.exe");  
        
        // TODO Auto-generated method stub
        String[] proxy = {"65.153.193.135:80","145.40.73.102:10004","203.189.142.168:53281","42.62.179.243:8080","200.24.146.68:999"};
        
        for(int i=0;i<proxy.length;i++)
        {
            
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--headless","--disable-gpu","--ignore-certificate-errors");
        options.addArguments("--proxy-server=https://" + proxy[i]);
        options.setAcceptInsecureCerts(true);
        
        
        WebDriver webDriver = new ChromeDriver(options);
        
        
        webDriver.get("https://www.google.com");
    
        System.out.println("Page title is : " + webDriver.getTitle()+ proxy[i]);
        webDriver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(5));
        webDriver.quit();
        
    }

    }
}

Errors:

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: net::ERR_PROXY_CONNECTION_FAILED (Session info: headless chrome=99.0.4844.51) Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 99.0.4844.51, chrome: {chromedriverVersion: 99.0.4844.51 (d537ec02474b5..., userDataDir: C:\Users\hp\AppData



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source