我的代码有效,但是在WebRequest
部分中,如果系统处于脱机状态,则会出现错误:
“无法解析此地址”
当存在Internet连接时,WebRequest起作用。我可以隐藏此错误吗?
#include <StringConstants.au3>
#include <Array.au3>
#include <String.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <InetConstants.au3>
#include <WinAPIFiles.au3>
Opt("RunErrorsFatal", 0)
Global $eRRor = ObjEvent("AutoIt.Error","MyErrFunction")
Func MyErrFunction()
; empty function
Endfunc
...some code here...
$oweb = ObjCreate("winhttp.winhttprequest.5.1");
$oweb.Open("POST",$TheUrl , False); ;Error happens here
$oweb.SetRequestHeader("Content-Type", "application/(a type)");
$oweb.SetRequestHeader("User-Agent", "(a random user agent)");
$oweb.Send($content);
...other code...
我也尝试过:
If @error Then
Exit
EndIf
但是如果错误(无声)发生,我想继续。
这是来自编译脚本(.exe文件)的错误。 8047行上的代码为$oweb.Send($content);
,但在调试时启用了错误详细信息:
在$oweb.Open("POST",$TheUrl , False);
上发生。
您应该创建单独的函数来执行单独的操作。每个函数应逐行具有@error处理!
每次使用每个功能时,都应检查错误。
在专业用途中使用任何计算机语言,都会导致您的代码中大约20%甚至更多的错误变为错误检查。
过去16年我用AutoIt编写程序,现在我知道我在说什么。