Forum Discussion

sarya's avatar
sarya
Frequent Contributor
14 years ago

how to handle exceptions during test suite runs

Hi,



I am running all the tests in the project at one time. Some of the tests have to verify the published files to local drives.If somehow the file is not published and it is not present in the folder,it pops-up an error message box asking to stop project execution.I click the option "No" whenever I am present during the test runs but how can I handle the exceptions like this when I am prseent at the time of the test runs. I am not sure as to where the exception will come as it can occur due to any test script. How and where I need to incorporate some code as to handle these exceptions of stopping at errors.



Thanks,

Sumedha

4 Replies

  • sarya's avatar
    sarya
    Frequent Contributor
    Hi David,



    I am explaining you the problem with the following example:



    function test()

    {

    code1.................

    .......................

    ExcelComp("C:\\Bur319.xls","C:\\myfiles\\PDF\\Burster\\Bur319.xls"); //It fails when it does not find the excel file for comparison

    ..........................

    ..........................

    code1

    }



    ExcelComp is a separate function where it calls another function createinfo()


    function createInfo(oExcel, fileName, aSheets)


    createInfo(oExcel, fileName, aSheets)

    {

    var oSheets;

    oExcel.Workbooks.Close();

    oExcel.Workbooks.Open(fileName);  //Exception occurs at this point when it tries to find a non-existing excel file

    oSheets = oExcel.Worksheets;

    sheetCount = oSheets.Count;

    ......................................

    //code

    }



    So I tried to use this code of try-catch and modifed createInfo function as but after logging the exception after catch block -I want to avoid going through rest of the code in createInfo() and go back again to the function test().How can I do that?



    function createInfo(oExcel, fileName, aSheets)

    {

    var oSheets;

    oExcel.Workbooks.Close();

    try{

    oExcel.Workbooks.Open(fileName);  //Exception occurs at this point when it tries to find a non-existing excel file

    }

    catch(e)

    {Log.Error("Exception occured",e.description);}

    oSheets = oExcel.Worksheets;

    sheetCount = oSheets.Count;

    ......................................

    //code

    }

    Thanks,

    Sumedha



  • Hi Sumedha,





    Just use the 'return' statement.





    try{

      oExcel.Workbooks.Open(fileName);  //Exception occurs at this point when it tries to find a non-existing excel file

    }

    catch(e)

    {

      Log.Error("Exception occured",e.description);

      return null;

    }
  • sarya's avatar
    sarya
    Frequent Contributor
    Thanks David.It works fine now.



    Thanks,

    Sumedha