Forum Discussion

scottb's avatar
scottb
Contributor
11 years ago

TC 10.40 is trapping exceptions between units


This goes back to an older issue with TC where it was not sending exceptions between units.  According to the documentation TC does not support cross-unit exception handling in JScript.  There was at least one thread a while back where this was discussed.



I was trying to find a workaround but discovered that my test script in JScript actually is handling cross-unit exceptions.  I have this:



[Unit1]

//USEUNIT Unit2



function t1() {

 try

 {

  Unit2.testThis2();

 } catch(e)

 {

  Log.Message(e.name+' - '+e.description);

 }

}



[Unit2]



function testThis2()

{

 1=2;

}



When I run Unit1.t1(), TC traps the exception thrown in Unit2.testThis2() and I get a nice message in the log with the name and description of the error.  I do not recall TC doing this in a previous version.



When I change the line

  Unit2.testThis2();

to

  Unit2.testThis2.call();

  

TC just logs an error and stops running when testThis2() executes.  It never makes it back to t1().  I also noticed some erratic crashes when I overrode Function.prototype.call in Unit2. 



Is Smartbear working on a workaround for the lack of cross-unit exception handling with JScript?  Is this a stable feature or do I just have a strange test system?


1 Reply

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi Scott, I have also found cross Script Unit Exceptions catchable so it is not just your test system.

     


    However, I have found they are not always caught, dependent on where they are thrown.


     


    My observations have been:


     


    1. If an Exception is thrown in a function that is declared in a Script Unit, it can be caught.


     


    2. If an Exception is nested, i.e. is thrown within an Object, Closure based Module or Script Extension, it cannot be caught.


     


    Unfortunately, as I want to use a single Exception handling pattern that works in any situation, I am still using messaging between Script Units to handle Exceptions instead of try catch.


     


    Regards,


    Phil Baird