malj67
15 years agoOccasional Contributor
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
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