Forum Discussion

malj67's avatar
malj67
Occasional Contributor
15 years ago

Handling All Exceptions in a Test

I am developing a custom test type for Quality Center (the TestComplete test type of course) and I am trying to figure out what is the best way to report back to Quality Center how things go, i.e. when a step starts or finishes and whether it is successful or not.     



There are basically two ways to do it. Either reporting can be done as the test is running, step by step, using the OnError event handler to detect any errors, or it can be done when the test has finished, by parsing the log file.    



If I am to use the first method, there is a problem. The OnError event handler does not handle exceptions in my VBScript code. There is a way to handle exceptions using On Error Resume Next which means that the next line will be executed when an exception occurs. It would however be more useful if we could use On Error GoTo Handler which means we could catch all exceptions in a test in a nice way.



Here are two examples of what works and what does not. TestComplete does not allow me to use the construction in the "ThisDoesNotWork" routine. Why is that? Is there no way to catch and handle all exceptions in a test? If not, I guess there is no other way to report results than parsing the test log after the test.   

 

Sub ThisWorks

  On Error Resume Next


  a = 1

  b = a/0


 


  If Err.Number <> 0 Then

    msgbox Err.Description

  End If


  On Error GoTo 0


End Sub





Sub ThisDoesNotWork


  On Error GoTo Handler


  a = 1

  b = a/0


 


  On Error GoTo 0

  Exit Sub



Handler:



  ' Handle exception here. 



End Sub


8 Replies

  • malj67's avatar
    malj67
    Occasional Contributor
    Sorry, guess that is only in VB then. My only option seems to be parsing the log then. I only wish there was a nice way to get the path to the log. But I guess I can look for the latest.   



  • sonu_davidson's avatar
    sonu_davidson
    Occasional Contributor
    Hi,



    Till now what ever you've handled is the error with the program what we wrote...



    Is it possible to get the application error as a msgbox..





    I've attached the image which shows the test logs.. From the test logs i've an error which says "Invalid Item Identifier"...

    My question is



    Is it possible to get that error in a message box???



    Pls reply..



    Thanks,

    Davidson
  • Hi,



    Handle the OnLogError event and display a message box in its handler. See the "Handling Events" and "aqDlg.MessageDlg" help topics.
  • sonu_davidson's avatar
    sonu_davidson
    Occasional Contributor
    Hi Alex,



    Thanks very much for your reply,



    I'm not clear with the one you asked me to do... Are you asking me enable that option or disable??





    Thanks

    Davidson
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi,



    As far as I remember the help, if this option is selected (i.e. checked), then TC should display error message window when an error occurs.

    Personally I was never interested in such behaviour and thus all my projects have this option not checked. But maybe for you selecting this option will do what you need.