David的测试技术空间,收藏好文档和分享我的技术理解。5年的数通产品测试和安全产品测试经验,3年Web产品测试和多年测试管理和测试工具开发经验。目前关注性能分析调优、Jmeter和TestNG+WebDriver+Hamcrest的培训推广。Welcome沟通交流,请留言或者发邮件到daviwang_2004 at soguo.com。

On Error Statement

上一篇 / 下一篇  2007-08-15 10:52:04 / 个人分类:QTP

from: QTP help

Enables or disables error-handling.

On Error Resume Next
On Error GoTo 0

Remarks

If you don't use anOn Error Resume Nextstatement anywhere in your code, any run-time error that occurs can cause an error message to be displayed and code execution stopped. However, the host running the code determines the exact behavīor. The host can sometimes opt to handle such errors differently. In some cases, the scrīpt debugger may be invoked at the point of the error. In still other cases, there may be no apparent indication that any error occurred because the host does not to notify the user. Again, this is purely a function of how the host handles any errors that occur.

Within any particular procedure, an error is not necessarily fatal as long as error-handling is enabled somewhere along the call stack. If local error-handling is not enabled in a procedure and an error occurs, control is passed back through the call stack until a procedure with error-handling enabled is found and the error is handled at that point. If no procedure in the call stack is found to have error-handling enabled, an error message is displayed at that point and execution stops or the host handles the error as appropriate.

On Error Resume Nextcauses execution to continue with the statement immediately following the statement that caused the run-time error, or with the statement immediately following the most recent call out of the procedure containing theOn Error Resume Nextstatement. This allows execution to continue despite a run-time error. You can then build the error-handling routine inline within the procedure.

AnOn Error Resume Nextstatement becomes inactive when another procedure is called, so you should execute anOn Error Resume Nextstatement in each called routine if you want inline error handling within that routine. When a procedure is exited, the error-handling capability reverts to whatever error-handling was in place before entering the exited procedure.

UseOn Error GoTo 0to disable error handling if you have previously enabled it usingOn Error Resume Next.

The following example illustrates use of theOn Error Resume Nextstatement.

On Error Resume Next
Err.Raise 6   ' Raise an overflow error.
MsgBox "Error # " & CStr(Err.Number) & " " & Err.Descrīption
Err.Clear   ' Clear the error.

TAG: QTP

 

评分:0

我来说两句

Open Toolbar