Forum Discussion

geethwind's avatar
geethwind
Contributor
12 years ago

How to use On Error Goto in Test Complete

I am trying to force the execution to the end when any error occurs.



How to use On Error Goto in Test complete ?



Ex:



Sub Main()



On Error Go to A:







A:

  log.message("Error")



end

3 Replies

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



    On Error GoTo <label> is not supported in VBScript (thus, this is not a problem of TC), but only On Error Resume Next and On Error GoTo 0 are supported.

    This makes VBScript the worst choice for the projects that expect runtime exceptions to occur often (one of the best examples is web services testing with negative tests, i.e. those, that feed web service with incorrect data and an error from web service is the expected result).

    Note, that execution of the On Error Resume Next in the beginning of the function is a bad programming practice as it hides runtime errors and you may get unexpected and strange results deeper in the code with a little chances to find out where the error actually occured.

    So the only approach for VBScript is to put On Error Resume Next before the line of code where you expect runtime error can occur, immediately after that line the

    res = Err

    line must be executed to save the current state of the Error object, On Error GoTo 0 must be executed then to enable run-time error handling and then you should analyse whether or not the runtime error occured using the

    If (0 <> res.Number) Then ... 

    code.

    Obviously, this clutters code and makes it more difficult to understand and support, but this is VBScript's specific you can do nothing with.
  • joffre's avatar
    joffre
    Regular Contributor


    Hello. I'm with the same doubt.



    I've seen the examples but I'm still stuck.



    Can anyone help me, please?



    My application is crashing every time, and I need to treat this.



    Thank you!