Barry Kelly
Re: Exceptions vs Error codes

Re: Exceptions vs Error codes

On Thu, 16 Aug 2001 23:45:52 +0100, Barry Kelly <✉>

>In article <✉>
>	Lord Crc <✉> wrote:
>> I often catch exceptions raised by TFilestream, so the
>> user can get a notice in a gracefull manner that the file is locked or
>> the free diskspace is no more.
>There, I think that's a bad idea.

An "EWriteError in ...." is more friendly to the users?

>> When sending streams as ISAPI responses, i free the stream object 
>> if an exception occurs. 
>Of course you do. That isn't a try..except block; that's a try..finally

Hmmz... I did isapi modules a year ago, so i checked up the help on 
TWebResponse.ContentStream and thought i must have dreamt that
TWebResponse took ownership of the stream (hence the except and not
finally). So i look up the code and: 

destructor TWebResponse.Destroy; begin   FContentStream.Free;

so my code basically goes like this:
   jpgOut:= TJPEGImage.Create;    try       // generate jpgOut
      ms:= TMemoryStream.Create;       try         jpgOut.JPEGNeeded;         jpgOut.SaveToStream(ms);       except         ms.Free;       end;
      Response.ContentStream:= ms;       Response.ContentStream.Position:= 0;       Response.ContentType:= 'image/jpeg';       Handled:= true;    finally       jpgOut.Free;    end;
is that flawed?
thanks for feedback - Asbj?rn
FYI: Phrase searches are enclosed in either single or double quotes
Originally created by
Tamarack Associates
Tue, 07 Feb 2023 05:14:50 UTC
Copyright © 2009-2023
HREF Tools Corp.