Your exception handler is only catching EIdHTTPProtocolException
exceptions specifically, but there are several other types of exceptions that can be raised as well, including EIdSocketError
. You need to update your handler accordingly, or just have it catch all possible exceptions instead of looking for specific types. Since you say an uncaught exception caused your entire app to fail (which means you have bigger problems to deal with than just TIdHTTP
), you should also update the code to handle exceptions raised by TMemoryStream
as well.
Try this:
// Connect to web server and download ToBeInstalled.ini
Url := 'http://'+IPAdd+'/ToBeInstalled.ini';
try
MS := TMemoryStream.Create
try
http.Get(url, MS);
code := http.ResponseText;
MS.SaveToFile(UserPath + 'ToBeInstalled.ini');
finally
MS.Free;
end;
except
on E: EIdHTTPProtocolException do begin
code := http.ResponseCode;
end;
on E: Exception begin
// do something else
end;
end;