Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Catch Exception - WHY??

Status
Not open for further replies.

ajbufort

Programmer
Apr 4, 2004
50
US
Hello All,

I have the following OnGet procedure in my code:

Code:
procedure TWebServer.OnGet(AThread: TIdPeerThread;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  Response: String;
  MemStream: TMemoryStream;
  Size: Integer;
begin
  CThread.Connection.WriteLn('SEND');

  Response := CThread.Connection.ReadLn;

  MemStream := TMemoryStream.Create;
  Size := CThread.Connection.ReadInteger;
  CThread.Connection.ReadStream(MemStream,Size,False);

  if not AThread.Terminated and AThread.Connection.Connected then
  begin
    try
      AResponseInfo.ContentStream := MemStream;
      AResponseInfo.WriteContent;
    except
      ShowMessage('Client not connected');
    end;
  end;
end;

When I open a 'client' (an html file designed to hit the address of this web server and make a GET request), I get the info I want, but when I close the browser window, I get one of two responses.

(1) No error at all.

(2) Socket Error #0

I assume that #2 is due to the fact that AResponseInfo.WriteContent; is still working just as the browser window is closing (thus closing the connection and causing an error). When the program errors out, that is the line it points to.

The oddest thing is - no matter what the exception is, I cannot catch it! My program insists on displaying an error dialog instead of whatever I have in my 'except' section. All i need to do is be able to catch that error and ignore it. What do i need to do here?

Thanks,

-Tony
 
Please, specify:

1) Exactly what error dialog you are getting (title and message).

2) What Delphi version you are using.

3) What Windows version you are using (SPs included).

4) If the error is being logged in the events log:
4.1) In what section of the log.
4.2) What the logged message say.

I believe you are facing an old problem Win32 have when confronted with closed handles or some memory faults, but I can't be sure without more info. If I'm true, the only solution I know is in some ways dangerous, so I prefer not to talk about without better knowledge.

buho (A).
 
Hi buho!

1) Project raised exception class EIdSocketError with message 'Socket Error #0'. Process Stopped'
2) Delphi 7
3) XP (SP1) and Win 2000 (SP4)
4) I had a TApplicationEvents component attached to my form, and had its OnException handler pointing to a method to log all exceptions to a file. That did not result in any output when these Socket Error #0 errors occurred.

Hey, hang on a sec - seems like when I run the executables outside of Delphi, the Socket #0 errors are gone. I either get no error, or the ShowMessage I wanted to display when I caught it! So apparently, i am catching it now.

-Tony
 
Ok. Check how your debugger is handling the exceptions :).

buho (A).
 
To help you further,

click on the menu 'Tools' and then 'debugger options' and then click on the tab 'language exceptions'. make sure that the checkbox 'stop on delphi exceptions' is not checked...

Cheers!

--------------------------------------
What You See Is What You Get
 
Thanks very much, guys. I appreciate you being there for those of us with questions.

-Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top