Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior Throw Behavior

Throw Behavior

Top  Previous  Next

You can simulate exceptions using Isolator++ Professional quite easily using the WHEN_CALLED(...).Throw() combination. This is helpful if you want to check your error handling code. In the following example, we'll simulate an exception thrown when the GetAgeFromFile is called:

 

class Person

{

public:

   int GetAge() { 

      try

 {

         return GetAgeFromFile();

 }

 catch

 {

                  return -1;

 }

   int GetAgeFromFile() { ... } 

};

 

 

 

TEST_F(Examples, Throwing)

{

   Person* personPtr = new Person();

   WHEN_CALLED(personPtr->GetAgeFromFile()).Throw("File doesn't exist");

   

   ASSERT_EQ (-1, personPtr->GetAge());

}

 

Note: You can throw any exception as long as it is actually throw within the code


Copyright  Typemock Ltd. 2009-2020.  All Rights Reserved.