Forum Discussion

n_v_isaev's avatar
n_v_isaev
Occasional Contributor
12 years ago

Exclusion from another unit

I use the TC 9 and Jscript

 


I need to catch exceptions when creating objects


"Stop on exceptions" and "Error dialog" in my project settings is disabled



Example:

Unit1:

function Class1(){

  throw new Error(-1,'error');

}



Unit2:

//USEUNIT Unit1

function test1(){

  try {

    Unit1.Class1();     // it works

    Log.Message('need stored'); 

 

  }

  catch (err){

    Log.Message('catch'); 

  }

}

 

 

function test2(){

  try {

    var object_of_Class1 = new  Unit1.Class1(); // It does not work

    Log.Message('need stored'); 

 

  }

  catch (err){

    Log.Message('catch'); 

  }

}



In test1 all good

In test2 exception is not caught.

How can I catch the exceptions in test2 case?
  • In my TC (9.1) your code works well, i have the exception caught in test2.



    I've adapted the Class1 like that:

    function Class1()

    {

      try {

        throw new Error('error');

      }

     

      finally {

      }

    }



  • bbi's avatar
    bbi
    Contributor
    In my TC (9.1) your code works well, i have the exception caught in test2.



    I've adapted the Class1 like that:

    function Class1()

    {

      try {

        throw new Error('error');

      }

     

      finally {

      }

    }



  • n_v_isaev's avatar
    n_v_isaev
    Occasional Contributor

    Maybe you forgot to write in Unit2


     


    / / USEUNIT Unit1  ?

  • n_v_isaev's avatar
    n_v_isaev
    Occasional Contributor

    Creepy looking, but working solution:


    What do you think about this?


     


    function test2(){


      try {


        var object_of_Class1 = eval('new '+Unit1.Class1+'()');


        Log.Message('need stored');     


      }


      catch (err){


        Log.Message('catch ='+err.description);  


      }


    }