I am using a domain with an untrusted TLS (SSL) certificate so I could debug something.
This is my code:
procedure test();
var
WinHttpReq: Variant;
begin
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
try
WinHttpReq.Open('POST', 'https://tv.eurosport.com/', False);
WinHttpReq.SetRequestHeader('Content-Type', 'application/json');
WinHttpReq.Send('');
except
MsgBox(IntToStr(WinHttpReq.Status), mbError, MB_OK);
end;
end;
In case there was an error with the request I would like to print the HTTP status code.
The problem is that the line in the except
clause is never executed and instead I get the following error:
Even if I run the executable without debugger attached it still causes errors.
How do I handle an OleObject
exception in Inno Setup?
As you expect, the WinHttpReq.Send
throws
The host name in the certificate is invalid or does not match
That exception is caught by your except
block. It's not true that the except
clause is never executed!
In the except
block you try to read the WinHttpReq.Status
(HTTP status code). But there's no HTTP status code yet, because the certificate validation happens before any HTTP exchange. So the second exception is thrown by the WinHttpReq.Status
getter:
WinHttp.WinHttpRequest: The data necessary to complete this operation is not yet available.
And you do not have any handler for that. So the exception is caught by the Inno Setup itself and displayed as "Runtime Error".