I've read error handling concepts & don't seem to make out how we can call a function when an error occurs while executing test script. Here is my requirement
script 1
code with error
immediately call a function that sends an email
First understand the difference between Error and Exception:
- Predictable Errors ~~> Error handling (By using "On Error Resume Next")
- Unpredictable Errors ~~> Exception Handling (By using "Recover Scenario Manager Wizard")
It's a bad practice to use On Error Resume Next. You should always try to clear all the predictable errors.
But to give you an example of how you can handle your predictable error using On Error, take a look at this code:
Code with error:
...
on error resume next
a = 1/0
If err.number <> 0 then
'Call function to send email
Call sendMail()
End If
...
Function sendMail()
'...
'Your code to send email
'...
End Function
This is how you can handle your predictable error. But if you have some unpredictable errors than you need to use Recovery Scenario Manager and for that Google is your best friend.