Trying to catch and throw exceptions if error message window is found I'm writing a test to validate that while clicking through a series of menu items, an error message pops up, and if it does, then I should throw an exception.

Now I wonder: Is it appropriate to use nested try-catch block here?

public static void main(String[] args) throws Exception{
        File file = new File("C:/Program Files/Selenium/IEDriverServer.exe");
        System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
        driver.get("http://ap-apbase-d002/Ecx.Web/Account/Login/?ReturnUrl=%2fEcx.Web%2f");
        WebElement element;
        element = driver.findElement(By.id("username"));
        element.sendKeys("Jh");
        element = driver.findElement(By.id("password"));
        element.sendKeys("1");
        element.submit();
        WebElement homeFrame = (new WebDriverWait(driver, 30)).until(ExpectedConditions.presenceOfElementLocated(By.id("pnCenter_IFrame")));
        driver.switchTo().frame("pnCenter_IFrame");
        WebElement myHomeLink = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.linkText("My Projects")));
        driver.findElement(By.linkText("My Projects")).click();
        driver.switchTo().defaultContent();
        driver.switchTo().frame("pnCenter_IFrame");
        driver.switchTo().defaultContent();
        //parent try block
        try{
        WebElement UniversalInboxLink = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.linkText("Universal Inbox")));
        driver.findElement(By.linkText("Universal Inbox")).click();
        WebElement MyProjectsLink = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.linkText("My Projects")));
        driver.findElement(By.linkText("My Projects")).click();
        WebElement AllProjectsLink = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.linkText("All Projects")));
        driver.findElement(By.linkText("All Projects")).click();
        WebElement MyTeamLink = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.linkText("My Team")));
        driver.findElement(By.linkText("My Team")).click();
        WebElement WOTTaxFormLink = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.linkText("WOT Tax Form")));
        driver.findElement(By.linkText("WOT Tax Form")).click();
        WebElement MyDraftsLink = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.linkText("My Drafts")));
        driver.findElement(By.linkText("My Drafts")).click();
        WebElement MyArchivesLink = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.linkText("My Archives")));
        driver.findElement(By.linkText("My Archives")).click();
        WebElement RetrieveLink = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.linkText("Retrieve")));
        driver.findElement(By.linkText("Retrieve")).click();
            //Child try block
            try{
        List &lt;WebElement&gt; AppbaseErrorWindow = driver.findElements(By.cssSelector(".x-window-header"));
        for (WebElement item : AppbaseErrorWindow) {
            if (item.getText().contains("Request Failure")) {
                //Do Nothing
            }
        }
            }catch (Exception e){
        System.out.println("Exception is found here: " + e);

            }
            System.exit(0);
            driver.quit();
    }
        catch(Exception e){
        System.out.println("All is OK.");
        }
        System.out.println("Normal behavior");
 }
The code that you submitted is not complete as it was missing the driver variable (Had to look up the type as I have not used Selenium).

private WebDriver driver;


First off move everything out of the main method even if you are going to only use one instance, whilst doing this you should also separate the code into single responsibility methods. This will improve the readability of the code and give the program a nicer "flow".

Methods you come to mind are:

private void init();
private void login(String username, String password);
private void clickElement(String element) throws Exception; 
private void processWebElements(String header);
private void terminate();


init() will be:

private void init() {
    // The driver you want to use
    driver = new FirefoxDriver();
    File file = new File("C:/Program Files/Selenium/IEDriverServer.exe");
    System.setProperty("weObdriver.ie.driver", file.getAbsolutePath());
    driver.get("http://ap-apbase-d002/Ecx.Web/Account/Login/?ReturnUrl=%2fEcx.Web%2f");
}


login() will be:

private void login(String username, String password) {
    WebElement element;
    element = driver.findElement(By.id("username"));
    element.sendKeys(username);
    element = driver.findElement(By.id("password"));
    element.sendKeys(password);
    element.submit();

    WebElement homeFrame = (new WebDriverWait(driver, 30)).until(ExpectedConditions.presenceOfElementLocated(By.id("pnCenter_IFrame")));
    driver.switchTo().frame("pnCenter_IFrame");
    WebElement myHomeLink = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.linkText("My Projects")));
    driver.findElement(By.linkText("My Projects")).click();
    driver.switchTo().defaultContent();
    driver.switchTo().frame("pnCenter_IFrame");
    driver.switchTo().defaultContent();
}


clickelement() will be:

private void clickElement(String element, int wait) throws Exception {
    WebElement universalInboxLink = (new WebDriverWait(driver, wait)).until(ExpectedConditions.presenceOfElementLocated(By.linkText(element)));
    driver.findElement(By.linkText(element)).click();
}


processWebElements() will be:

private void processWebElements(String header) {
    List&lt;WebElement&gt; AppbaseErrorWindow = driver.findElements(By.cssSelector(header));
    for (WebElement item : AppbaseErrorWindow) {
        if (item.getText().contains("Request Failure")) {
            //Do Nothing
        }
    }
}


finally terminate() will be:

private void terminate() {
    System.exit(0);
    driver.quit();
}


This way you can easily change a bit of the program without rewriting for every time you wanted to call do something. Your try-catch can also be unested as the try inside will only start when everything inside the outside try block is finished. Using the above functions my constructor would be as follows:

public WebAuto() {
    init();
    login("Jh", "1");

    try {
        clickElement("Universal Inbox", 10);
        clickElement("My Projects", 10);
        clickElement("All Projects", 10);
        clickElement("My Team", 10);
        clickElement("WOT Tax Form", 10);
        clickElement("My Drafts", 10);
        clickElement("My Archives", 10);
        clickElement("Retrieve", 10);
        terminate();
    } catch (Exception e) {
        System.out.println("All is OK.");
    }

    try {
        processWebElements(".x-window-header");
    } catch (Exception e) {
        System.out.println("Exception is found here: " + e);
    }
    System.out.println("Normal behavior");
}


Extra: You should set up constants for strings such as file locations.