【发布时间】:2019-09-21 07:04:02
【问题描述】:
我的代码可以工作,但是在WebRequest部分,如果系统离线,就会出现错误:
“无法解析此地址”
当存在互联网连接时,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-handling runtime-error try-catch autoit suppress-warnings