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 occured here; Log.Error("Error occured in foo"); } function GeneralEvents_OnLogError(Sender, LogParams) { Log.Message("handling error");
handlingError();
Log.Message("further handling error"); futherHandlingError(); Log.Message("initializing stuff");
initializingStuff();
//...and stop current test
Runner.Stop(true); }
Now in the final cumulative test log, the message from the function foo() will be placed at the very end of the log thread, sth. like this:
handling error
further handling error
initializing stuff
Error occured in foo
Is there a way to log the real error message at the beginning of the log thread to prevent confusion, like this:
Error occured in foo
handling error
further handling error
initializing stuff
Many thanks for any hints.
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.
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); }