softtouch 9 Posted March 6, 2023 I use TIdHTTP to read some websites. The TIdHTTP.get is within a try/except block. I am not able to catch the 2 exceptions: Socket error # 53, Software cause connection abort and Socket error # 61, Connection refused. It does not happen on my machine, but on some client computer. It also does not happen when compiling the program for Windows. All I have is this in the stack trace: Idstack::TIdStack::RaiseLastSocketError() + 62 Idstack::TIdStack::CheckForSocketError(int) + 33 Idstackvclposix::TIdStackVCLPosix::Connect(int, System::UnicodeString, unsigned short, Idglobal::TIdIPVersion) + 233 Idsockethandle::TIdSocketHandle::Connect() + 44 Idiohandlerstack::TIdConnectThread::Execute() + 28 The exception is ok, but why cant I catch this so that the program can show an error and continue running instead of just crashing? The call to TIdHTTP.get is in try/except similar this: id:=TIdHttp.create(nil); try val:=id.get(url); except on e: Exception do begin end; end; id.free; Share this post Link to post
Remy Lebeau 1398 Posted March 6, 2023 (edited) 11 hours ago, softtouch said: All I have is this in the stack trace: Idstack::TIdStack::RaiseLastSocketError() + 62 Idstack::TIdStack::CheckForSocketError(int) + 33 Idstackvclposix::TIdStackVCLPosix::Connect(int, System::UnicodeString, unsigned short, Idglobal::TIdIPVersion) + 233 Idsockethandle::TIdSocketHandle::Connect() + 44 Idiohandlerstack::TIdConnectThread::Execute() + 28 When the client's ConnectTimeout property is set to a non-infinite value, or if you are connecting the client in the context of the main UI thread and using TIdAntiFreeze, then Indy uses a worker thread to connect the client socket to the server in order to implement timeout handling. The call stack above is showing the exception being raised in the context of that worker thread, and there is no way for you to catch that specific exception directly from that thread. However, Indy will internally catch the exception for you and re-raise it in the context of the thread that is trying to connect the client. And you should be able to catch that exception normally. If not, then the RTL is likely not doing its job correctly (IIRC correctly, Delphi's exception handling on MacOS is less stable/reliable than on Windows). Quote The exception is ok, but why cant I catch this so that the program can show an error and continue running instead of just crashing? The code you have shown is fine, you should be able to catch the exception. So, you are just going to have to debug the code at runtime to find out why the exception is not being propagated to your code correctly. Edited March 6, 2023 by Remy Lebeau 1 Share this post Link to post