ON ERROR

C++ Test Script Language

Syntax

ON ERROR [ { <error item> } ] <error action>;

Location

C++ Test Driver Script, TEST CLASS, TEST SUITE, TEST CASE, PROC

Description

The ON ERROR statement defines the behavior of the test driver when an error occurs.

ON ERROR applies to the current scope level, and to nested scopes, unless another ON ERROR statement has been defined. The general rule is that the most nested ON ERROR statement is applied.

Note   An error can be raised by any instruction of a TEST CASE or a PROC, and by native code from a PROLOGUE or EPILOGUE.

ON ERROR does not apply to stubs. There is always an implicit ON ERROR CONTINUE behavior in stubs

<error item> may be one of the following entities:

This block is executed when an error occurs.

<error action> is a keyword which defines the behavior of the test driver when an error occurs:

Example

ON ERROR CONTINUE;

TEST CLASS A {

       ON ERROR EXIT;

       TEST SUITE A1 {

              ON ERROR BYPASS A;

              TEST CASE A1a {

                     ON ERROR CONTINUE;

                     CHECK (false); // this leads to an error but execution continues

                     PRINT "ok"; // this instruction is executed

              }

              TEST CASE A1b {

                     CHECK (false); // this leads to an error

                                  // execution resumes after TEST CLASS A
      
              PRINT "ko"; // this instruction is never executed

              }

       }

       TEST CASE A2 {

              CHECK (false); // this leads to an error -- the test driver exits

              PRINT "ko"; // this instruction is never executed

       }

       RUN { A1; A2; }

}

TEST CLASS B {

       TEST CASE B1 {

              ON ERROR BYPASS;
      
       CHECK (false); // this leads to an error -- execution resumes after B1

              PRINT "ko"; // this instruction is never executed

       }

       TEST CASE B2 {

              CHECK (false); // this leads to an error but execution continues

              PRINT "ok"; // this instruction is executed

       }

       RUN { B1; B2; B1; }

}

RUN { B; A; A.A2; }

 

In this example, the execution is: B1 (aborted), B2, B1 (aborted), A1a, A1b (A is aborted), A2 (exited).