Forum Discussion

scrier's avatar
scrier
Contributor
12 years ago

Can't catch exceptions from extensions.

Hello, 



I have the following issue (somewhat simplified):



I have an extension in javascript that evaluates parameters in and if necessary throws an exception. Problem is that if the extension script throws the exception, TestComplete cannot catch it. Here is a simple test showing the issue:



extension.js:


function testThrow()

{

  throw new CustomException("Catch!!!");

}





function CustomException(text)

{

  this.name="CustomException";

  this.message=text;

}



description.xml:



<?xml version="1.0" encoding="UTF-8"?>

<ScriptExtensionGroup>

  <ScriptExtension Name ="Test Object" Author="me" Version="0.1" HomePage="None">

    <Script Name ="extension.js">

      <RuntimeObject Name="Tests" Namespace="TEST">

        <Method Name="testThrow" Routine="testThrow">

        </Method>

      </RuntimeObject>

    </Script>

  </ScriptExtension>

</ScriptExtensionGroup>



testfunction in testcomplete:


function TestThrow()

{

  try {

    TEST.Tests.testThrow();          

  } catch(ex) {

    Log.Message(ex.name + ": " + ex.message);

  }

}


I get the screenshot as listed below and it works if I throw in testcomplete, but not between extension and testcomplete.



// Andreas




2 Replies

  • Gordian's avatar
    Gordian
    Occasional Contributor
    I am also interested to know if this is a limitation.



    There is an internal variable as shown below that could be used and then checked by the user's script / keyword test.   Is that the recommended approach?





    var number;

    var last_status;  // An internal variable that holds the LastStatus property value




    // The set method of the Number property


    function SetNumber(Value)

    {

      try


      {

        number = aqConvert.VarToInt(Value);

        last_status = 0;  // The property value has been successfully modified


      }

      catch (e)

      {

        last_status = e.number;  // An error indicating that Value could not be converted to an integer


      }

    }