I'd like to elaborate on how to properly handle fatal network exceptions raised by TIdHTTP
inside TThread's Execute
procedure.
My app runs a while..do
loop inside the Execute
procedure. Each loop makes a TIdHTTP.Get()
call. The exceptions are handled at the loop level. There is also an upper level handler of on E: Exception do
(level of Execute
).
The scenario assumes a fatal network error during active network operations (i.e. adapter outage, "connection reset by peer", etc.).
10 threads are serialized to make TIdHTTP.Get()
requests from inside the loop. The app is running on a laptop when a home router unexpectedly hangs. Here comes #10054. Suppose that the network returns within 10 minutes. I want to make sure that in case of a sudden network death, each thread somehow:
- Detects that (well, that's the easiest).
- Waits until the network comes back.
- Makes sure the network is up.
- Re-establishes connection and restores all network hood.
- Continues the loop.
The desired result is to keep the thread up and running and just survive the temporary network problem. The threads must periodically check if the network is back. When it is, the exception handler must restore all network hood calling thread's RestoreNetworkConnection
and then continue the loop.
What I definitely don't want - is to stop threads' execution.
Questions
- Which events/exceptions shall I intercept to handle fatal network errors?
- Where to place exception handlers within
Execute
? - What is correct way of re-establishing connection back to normal state?