Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use TIdHttp inside TThread anonymous function doesn't raise exceptions
#6
(09-03-2020, 04:00 AM)Ahmed Sayed Wrote: when I send a request to a server that is not running, supposedly I should get an error "connection refused" because the client can't connect to the server in the first place.

That is one possible error, yes.  There are other possible socket errors.  But yes, all non-HTTP errors would be handled by your outer catch (Exception &E) block (which BTW, should be catching by const reference, just as you are doing when catching EIdHTTPProtocolException).

(09-03-2020, 04:00 AM)Ahmed Sayed Wrote: Now I if understand this correctly that type of errors are not internal server error and should be caught outside the thread executing the request.

They will be thrown in the same thread that is executing the HTTP request.  You would have to catch and delegate them to other threads as needed.

(09-03-2020, 04:00 AM)Ahmed Sayed Wrote: Now what I was trying to achieve is to make sure that all returned content from the server whether it is an error or not must be displayed in Memo, all other exception must be caught in a normal Message box.

And that is fine, and the code I have given you should be doing exactly that.

(09-03-2020, 04:00 AM)Ahmed Sayed Wrote: Now just to understand this correctly If I want to make TIdHTTP behave the same way as TRestRequest I must enable both hoWantProtocolErrorContent, hoNoProtocolErrorException So that content is passed to Response ContentStream. Right?

That is one way to do it, yes.  The other way is to catch EIdHTTPProtocolException and copy its ErrorMessage text into your target TStream.

Reply


Messages In This Thread
RE: Use TIdHttp inside TThread anonymous function doesn't raise exceptions - by rlebeau - 09-03-2020, 05:19 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)