Forum Discussion

marin's avatar
marin
Frequent Contributor
9 years ago
Solved

How to log error at the beginning of the OnLogError handler

Hello all,   I wonder if it is possible to somehow determine when the error message will be logged within the OnLogError handler? We have following situation:   function foo() { //error occure...
  • Marsha_R's avatar
    Marsha_R
    9 years ago

    Well, the definition of the OnLogError Event http://support.smartbear.com/viewarticle/68044/ says

    "The event occurs before an error message is posted to the test log."

     

    so I don't think you can redefine that.

     

    If you just want to make things easier to read in the log, try putting Append Log Folder at the top of the error handler function and Pop Log Folder at the bottom.  This will indent the error handling and organize the log a little more.  

     

    See attached screenshots.

     

     

     

     

     

  • AlexKaras's avatar
    9 years ago

    Hi Marin,

     

    The possible (though not verified) implementation might be like this:

    -- create a public flag that indicates if the code is in the error handler or not;

    -- post an error from the eror handler;

    -- continue wih the other stuff in the error handler.

     

    I.e. something like this:

     

    var boolIsInErrorhandler = false;

    function GeneralEvents_OnLogError(Sender, LogParams) {
    if (boolIsInErrorHandler) then
    return;

    boolIsInErrorHandler = true;
    Log.Error(<initial error from LogParams>)
    boolIsInErrorHandler = false;
    Log.Message("handling error");
    handlingError();
    Log.Message("further handling error"); futherHandlingError(); Log.Message("initializing stuff");
    initializingStuff();
    //...and stop current test
    Runner.Stop(true); }