函数参考
SetError
设置宏 @error 的值.
参数
错误码 |
为@error宏设置一个用户指定的值(整数). |
扩展值 |
[可选参数] 为@extended宏设置一个值(整数). 这个设置也可以使用 SetExtended() 函数进行设置. |
返回值 |
[可选参数] 忽略默认值并返回设置的值. |
返回值
By default, none, however if the optional return value argument is passed, then the function will return that value.
注意/说明
When entering a function @error is set to 0. Unless SetError() is called, then @error will remain 0 after the function has ended. This means that in order for @error to be set after a function, it must be explicitly set. This also means you may need to backup the status of @error in a variable if you are testing it in a While-WEnd loop.
The extended parameter is optional. It is only provided as a way to set both @error and @extended at the same time. If only @extended needs set, then it is recommended to use the SetExtended() function instead.
相关
SetExtended
示例/演示
Local $iResult = myDiv(5, 0)
If @error Then
MsgBox(4096,"错误", "除数为 0")
Else
MsgBox(4096, "结果", $iResult)
EndIf
Exit
Func myDiv($iDividend, $iDivisor)
If $iDividend = 0 And $iDivisor = 0 Then
SetError(2) ;表达式为 0/0
ElseIf $iDivisor = 0 Then
SetError(1) ;除数为 0
EndIf
Return $iDividend / $iDivisor
EndFunc ;==>myDiv