title: Jenkins displays "Build Success" even when tests are failed due to error handling in scripts (try and catch block)
body: <p><strong>Note</strong>: I am unable to paste the exact framework and code as the server I work on is not accessible from outside. Hence, I will try to explain my problem in simple words and examples.</p>
  
  <p><strong>Overview</strong> - I have created a Selenium automation framework which includes TestNG, Maven (POM.XML), Test data files, Scripts and few reusable functions. </p>
  
  <p><strong>Issue I am facing</strong> - I use Jenkins to execute my scripts. Jenkins calls POM.XML file which inturn calls testng.xml file (In testng.xml file, I have mentioned the scripts to be executed)</p>
  
  <p>Let's say, I have to perform login action</p>
  
  <p><strong>Main Script</strong></p>
  
  <pre><code>@Test
  Public void maintest ()
  {
  
  //I use Extent reports for reporting purpose and hence I have created extent 
   //reporting reusable function which is called in the below fashion.
  
  //If Login method returns pass, ExtentReportingFunc passes Pass to its 
   //function and displays Pass for that particular Login step in the report.
  
  ExtentReportingFunc (Login(UserName, Password));
  }
  </code></pre>
  
  <p><strong>Reusable functions</strong></p>
  
  <pre><code>Public String Login (String UN, String Pass)
  {
  //Sendkeys and set UN
  driver.findelement (By.id("username")).sendkeys(UN);
  
  //Sendkeys and set Password
  driver.findelement (By.id("password")).sendkeys(pass);
  
  //Click Login
  driver.findelement (By.id("login")).click ();
  
  //Verifying the message "Welcome User" is displayed after login
     try 
     {
        if (driver.findlement (By.id("welcomemessage")).isdisplayed ();
        {
          return pass;
        }
     } catch (Exception e)
     {
       //If welcome message is not found then return fail to the Reporting function
       return "fail";
  
       //Below code will be unreachable which is correct as per Java but that is the challenge.
        // I tried several ways to find a work around to return fail as above as 
        // well throw exception but no luck till now.
        // Upon throwing exception in the below way, Jenkins displays build as 
        //failed. If it is not done, though the script has failed, 
        //Jenkins displays "BUILD PASSED"
  
         throw e;
     }
  }
  
  //Extent Reporting function
  ExtentReportingFunc (String status)
  {
  log.report (status);
  }
  </code></pre>
  
  <p>Here, the challenge is - In the catch block, If I DO NOT mention "throw e", Jenkins won't understand that the failure has occurred and display "BUILD PASSED" in it's console output. I want it to display "BUILD FAILURE" in Jenkins console. Reason why I want it to display "BUILD FAILED" is - I have integrated JIRA with Jenkins. Only when jenkins show BUILD FAILED, it logs automatically bugs to JIRA. If it is "BUILD PASSED" and though finished status is UNSTABLE, no failures will be displayed in the test result section of Jenkins NOR it logs any bugs in JIRA.</p>
  
  <p>However, that time I won't be able to pass return "fail" to the main reporting function so that it can display login step as failure in the report.</p>
  
  <p>I understand, as per JAVA we can either throw or return in the catch block but not both. Is there any other way we can make this work?</p>
  
  <p>I already had created end to end framework but later realised this problem when I started integrating with Jenkins (or else everything was fine till then).</p>