An Object is an instance of a Class. It consists of methods and properties. We can create our own objects or we can use the existing objects in VB.
Consider the following statements,
Print "a"
Print CInt("a3")
Print "b"
The above code will stop the execution at the second step. But, what if we do not want the execution to stop?
For this, we use the statement - 'On Error Resume Next'. This statement tells UFT that even if an error appears, then execution won't stop. Hence, the code will become:-On Error Resume Next
Print "a"
Print CInt("a3")
Print "b"
Err Object
Now, the code will execute completly without stopping in between. But, we shall report that the error was occured during execution. For this, we use Err object and its Description property.
On Error Resume Next
Print "a" & Err.number
Print CInt("a3")
Print "b" & Err.number
If Err.Number<>0 Then
msgbox Err.Description
End IfOutput:
a0
b13
Type Mismatch
Hence, the Error value changes from 0 to something other than 0, if an error occurs. And, the Error Description - 'Type Mismatch' is shown.
Clearing an Error from memory -
To clear the Error from the memory, we use, Err.Clear. Using Err.Clear method, Err object is reset.
So, if we write Err.Clear after above lines and try printing the Err.number again then it will return 0.
Raising an Error Deliberately -
At times we need to raise an error deliberately. For this we use the following commands,
On Error Resume Next
Err.raise 10
print err.Description
Output: "The array is fixed or temporarily locked."
Hence, an error message corresponding to error number 10 is displayed."
More details on Err object can be studied from UFT Help as well.
=================**********************===================
Consider the following statements,
Print "a"
Print CInt("a3")
Print "b"
The above code will stop the execution at the second step. But, what if we do not want the execution to stop?
For this, we use the statement - 'On Error Resume Next'. This statement tells UFT that even if an error appears, then execution won't stop. Hence, the code will become:-On Error Resume Next
Print "a"
Print CInt("a3")
Print "b"
Err Object
Now, the code will execute completly without stopping in between. But, we shall report that the error was occured during execution. For this, we use Err object and its Description property.
On Error Resume Next
Print "a" & Err.number
Print CInt("a3")
Print "b" & Err.number
If Err.Number<>0 Then
msgbox Err.Description
End IfOutput:
a0
b13
Type Mismatch
Hence, the Error value changes from 0 to something other than 0, if an error occurs. And, the Error Description - 'Type Mismatch' is shown.
Clearing an Error from memory -
To clear the Error from the memory, we use, Err.Clear. Using Err.Clear method, Err object is reset.
So, if we write Err.Clear after above lines and try printing the Err.number again then it will return 0.
Raising an Error Deliberately -
At times we need to raise an error deliberately. For this we use the following commands,
On Error Resume Next
Err.raise 10
print err.Description
Output: "The array is fixed or temporarily locked."
Hence, an error message corresponding to error number 10 is displayed."
More details on Err object can be studied from UFT Help as well.
=================**********************===================
No comments:
Post a Comment