On Error Resume Next

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

QTP采用VBS作为脚本语言,VBS中处理错误的语句是:

On Error Resume Next
On Error GoTo 0

If you don't use an On Error Resume Next statement 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 behavior. The host can sometimes opt to handle such errors differently. In some cases, the script 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 Next causes 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 the On Error Resume Next statement. This allows execution to continue despite a run-time error. You can then build the error-handling routine inline within the procedure.

An On Error Resume Next statement becomes inactive when another procedure is called, so you should execute an On Error Resume Next statement 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.

Use On Error GoTo 0 to disable error handling if you have previously enabled it using On Error Resume Next.

The following example illustrates use of the On Error Resume Next statement.

On Error Resume NextErr.Raise 6   ' Raise an overflow error.MsgBox "Error # " & CStr(Err.Number) & " " & Err.DescriptionErr.Clear   ' Clear the error.

Err对象包含运行时的错误信息。

Raise方法用于产生运行时错误

Clear方法用于清除运行时错误。

Description属性存储了错误相关的描述信息。

Number属性是指错误号。

Source属性是指产生错误的源头对象或应用程序名。

The Err object is an intrinsic object with global scope — there is no need to create an instance of it in your code. The properties of the Err object are set by the generator of an error — Visual Basic, an Automation object, or the VBScript programmer.

The default property of the Err object is Number. Err.Number contains an integer and can be used by an Automation object to return an SCODE.

When a run-time error occurs, the properties of the Err object are filled with information that uniquely identifies the error and information that can be used to handle it. To generate a run-time error in your code, use the Raise method.

The Err object's properties are reset to zero or zero-length strings ("") after an On Error Resume Next statement. The Clear method can be used to explicitly reset Err.

The following example illustrates use of the Err object:

On Error Resume NextErr.Raise 6   ' Raise an overflow error.MsgBox ("Error # " & CStr(Err.Number) & " " & Err.Description)Err.Clear      ' Clear the error.

在QTP中除了使用VBS的On Error Resume Next来处理错误外,还可以采用以下两种方式来处理:

1、设置Test Settings中的“When error occurs during run session”

By default, if an error occurs during the run session, QuickTest displays a popup message box describing the error. You must click a button on this message box to continue or end the run session.

You can accept the popup message box option or you can specify a different response by choosing one of the alternative options in the list in the When error occurs during run session box:

proceed to next action iteration . QuickTest proceeds to the next action iteration when an error occurs.
stop run . QuickTest stops the run session when an error occurs.
proceed to next step . QuickTest proceeds to the next step in the test when an error occurs.

QuickTest first performs any recovery scenarios associated with the test, and performs the option selected above only if the associated recovery scenarios do not resolve the error.

2、设置恢复场景(Recovery Scenario)

http://blog.csdn.net/Testing_is_believing/archive/2008/03/17/2193021.aspx

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow

这里写图片描述

猜你喜欢

转载自blog.csdn.net/gdhjgfr/article/details/84141925