Delphi Socket Error Exception
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us
Delphi Socket Error 10061
Learn more about Stack Overflow the company Business Learn more about hiring developers delphi socket error 10060 or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack delphi socket error 10054 Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up TIdHTTP exception handling up vote 0 down vote
Socket Error 11004 Delphi
favorite I created a program that automatically connects to our local server and downloads updates, here is the code: // Connect to web server and download ToBeInstalled.ini Url := 'http://'+IPAdd+'/ToBeInstalled.ini'; MS := TMemoryStream.Create try try http.Get(url, MS); code := http.ResponseText; except on E: EIdHTTPProtocolException do code := http.ResponseCode; end; MS.SaveToFile(UserPath + 'ToBeInstalled.ini'); finally http.Free(); end; The program works quite well while in the office but when users
Socket Error 11001 Delphi
are home and cannot reach the server or the server is not available the get "socket error # 10061' I have no idea how to catch that one and the worse is that the program stop execution all together after that error message is displayed. Do you have any idea how to fix that. Thank you so much. delphi delphi-xe2 indy10 share|improve this question asked Apr 28 '13 at 22:55 Cor4Ever 951413 add a comment| 1 Answer 1 active oldest votes up vote 6 down vote accepted 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;
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business python socket error exception Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
Delphi Raise Exception
Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up getting asynchronous socket error 10049 even if i use try..except up vote 3 down vote favorite when ever i run my program(outside the http://stackoverflow.com/questions/16268913/tidhttp-exception-handling debugger/ide) i get error asynchronous socket error 10049, am i not supposed to recieve a message dialoge : ''error''? see my code below begin try ClientSocket1.open; except showmessage('error'); end; end; what am i doing wrong? delphi sockets exception-handling try-finally tclientsock share|improve this question asked Aug 1 '10 at 16:09 Omair Iqbal 1,0601639 add a comment| 2 Answers 2 active oldest votes up vote 4 down vote accepted What you should do is handle the Error http://stackoverflow.com/questions/3382707/getting-asynchronous-socket-error-10049-even-if-i-use-try-except event of the TClientSocket, because that is where you will be able to capture your socket errors. The ErrorCode parameter is the one that will have the WinSock Error code If you want to silence the Error, you can set ErrorCode to 0, which will prevent the exception from being thrown, and after that you can identify what the error is and handle it the way you want it procedure TForm1.ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer); var error : Integer; begin error := ErrorCode; {prevent exception from being thrown} ErrorCode := 0; if error = 10049 then showmessage('asynchronous socket error'); . . . end; I hope this helps Gaetan Siry share|improve this answer answered Aug 1 '10 at 19:59 G-Man 3,600124575 thanks a heap.... –Omair Iqbal Aug 2 '10 at 6:13 add a comment| up vote -1 down vote The TClientsocket component (which is deprecated for a while already) uses the asynchronous communication model, so it is possible that the exception is not thrown in the Open method but in the message / event handling method which receives the incoming data. update: I can reproduce this with Delphi 6 and the given code, if I enter an invalid IP address like 1.2.3.4 To fix it I would move to a TCP/IP library like Indy or Ararat Synaps
face of it seems to be a simple error. I am currently testing a Delphi 5 app. that connects to a server process running on our UNIX machine. In order to test the exception handling, I brought down the server on the UNIX box and tried to connect from the Delphi app. The 'connect' is as follows : [SNIP] with sckClient http://www.delphigroups.info/2/71/75623.html do begin Host := strHost; Port := intPort; try Open; except on ESocketError do MessageDlg('SOCK Error', mtError, [mbOK], 0); exit; end; end; I'm expecting an ESocketError as the peer is not there. I _do_ get an exception but it is not caught by the exception block (even if I use on Exception...). The message reads :- socket error Windows socket error (10110), on API 'Async Lookuop' Does anyone know why this cannot be caught: I want to end gracefully if the connection attempt fails ideally ;) It looks like a different exception may well be getting thrown here though there is nothing to suggest what it is in the documenation AFAIK. In fact in debug mode, the de{*word*81} _does_ report an ESocketError ;( Any help gratefully received...thanks, Kev TP Delphi Developer Wed, 08 Sep 2004 02:05:48 GMT Re:Windows Socket exception cannot be caught ?? Hi, You have to use the event 'OnError' of the socket component. delphi socket error In that event, set the errorcode to zero and put your own message there I hope this helps. Regards, Kevin. "Kev Grindley"