title: How to pass error message from method causing exception to onTestFailure method in Listener
body: <p>I am trying to print exception message from method which causing exception to testng listener so that I can print it in extent report. I have written code like this</p>
  
  <pre><code>@Override
  public void onTestFailure(ITestResult result) {
      String screenshotPath = "";
      try {
          screenshotPath = ScreenshotUtil.capture();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      try {
          test2.log(Status.FAIL, MarkupHelper.createLabel("Error occured", ExtentColor.RED));
  
          test2.addScreenCaptureFromPath(screenshotPath, "Error");
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>and I am throwing exception in below method</p>
  
  <pre><code>public HomePage assertLoginSuccessful(boolean flag, String name) throws ExplicitAssertionError, IOException{
          waitForPageToLoad();
          WebDriverWait wait=new WebDriverWait(getDriver(), 5);
          String xpath="//a[@id='welcome'][contains(.,'Welcome "+name+"')]";
          try{
          wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath(xpath)));
          if (flag){
                  List&lt;WebElement&gt; list=getDriver().findElements(By.xpath(xpath));
  
                  if (list.size()==0){
                      throw new ExplicitAssertionError("User name"+name+" not found hence login not successful");//this message should be passed to listener
                  }
          }
          }catch (Exception ex){
              throw new ExplicitAssertionError("User name"+name+" not found hence login not successful");
          }
          return this;
  </code></pre>