Forum Discussion

JanTkacik's avatar
JanTkacik
New Contributor
14 years ago

JScript exception propagation between script units problem in TestComplete 8.5

Good day,


I am experiencing a problem with exception propagation. Similar problems has been discussed here in forum before and I have read that this feature (Exception propagation between script units) has been implemented in TestComplete 8.




I am using TestComplete 8.5. and with code like this:



---------------------------------------------------------------

                                Unit TestC

---------------------------------------------------------------



//USEUNIT TestB



function classC()

{

    this.c = new TestB.classB();

}



classC.prototype.test = function test()

{

    try

    {

        this.c.exNotThrower();

    }

    catch(e)

    {

        Log.Error(e.description);

    }

}



function test()

{

    var a = new classC();

    a.test();

}



-----------------------------------------------------------------

                                    Unit TestB

-----------------------------------------------------------------

//USEUNIT TestA



function classB()

{

    this.b = 5;

}



classB.prototype.exNotThrower = function exNotThrower()

{

    //try

    //{

           var a = new TestA.classA();

            a.exThrower();  

    //}

    //catch(e)

    //{

    //     throw e;

    //}   

}



-----------------------------------------------------------------

                                Unit TestA

-----------------------------------------------------------------

function classA()

{

    this.a = 5;

}



classA.prototype.exThrower = function exThrower()

{

    throw new Error(-1,"Testing exception");

}



exception from Unit TestA is propagated niether in TestB nor TestC.

Has someone similar problem ? What`s your solution or workaround ?


Thanks in advance


Jan Tkacik


FFastfill

4 Replies

  • JanTkacik's avatar
    JanTkacik
    New Contributor

    I found a solution myself.



    If code goes like this:



    function c
    lassA()

    {

        this.a = 5;

        this.exThrower = function exThrower()

        {

            throw new Error(-1,"Testing exception");

        }

    }



    it works properly.  



  • Hi Ján,



    Currently, cross-unit exception handling in JScript works out of the box only for global functions. Exceptions raised by instance functions and prototype functions, like in your example, aren't passed between units.



    The workaround is to redefine the prototype functions that throw exceptions in the unit where these exceptions are handled. Like this, for example:



    ---------------------------------------------------------------

    Unit TestC

    ---------------------------------------------------------------



    //USEUNIT TestB



    var str_classA_exThrower_Code = TestA.classA.prototype.exThrower.toString();

    eval("TestA.classA.prototype.exThrower = " + str_classA_exThrower_Code);



    function classC()

    {

      ...




    Please refer to Supported Scripting Languages - Specifics of Usage for more details on TestComplete's cross-unit JScript support.