Re: Debuggen von Critical Sections



Hans-Peter Diettrich schrieb:

end (* if myStatus=stOpen: datei geöffnet/angelegt *)
else ??????
end;

Das ist natürlich kritisch :-(
Wenn die obere Schleife *nicht* mit myStatus=stOpen verlassen wird, dann
wird der FileStream nicht mehr freigegeben!

Dann wurde er aber auch gar nicht erst angelegt!

Ich würde die Trys anders schachteln:

... until myFileStream <> nil;

Ist ein Objekt denn wirklich nil, wenn es nicht angelegt werden
konnte, weil im Constructor eine Exception auftrat?

try
if myStatus = stOpen then ... [1]
//else??? schon mal dran gedacht?
finally
myFileStream.Free;
end;

Das klappt aber nur dann, wenn ein nicht-erzeugbares Objekt
(Exception im Constructor) wirklich nil zurückliefert. So
deutlich habe ich das IIRC noch nirgendwo gelesen. Ist das
wirklich immer und überall so?

Bei mehrwertigen Status-Typen halte ich es für empfehlenswert, die im
Zweifelsfall nicht mit If auszuwerten, sondern mit Case [...]

Stimmt, das baue ich dann in Version 2.0 noch ein :-)

Gruß Matthias.
.



Relevant Pages

  • Re: throwing exception from constructor
    ... The FileStream constructor is another example of a poor design choice. ... opening a file is not a simple operation. ... there'd still be an exception occurring. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem with FileStream - FileNotFoundException
    ... impersonation must be turned off. ... I have the following problem with FileStream. ... User on which application is running has full permision to the destination folder. ... I've cheked other constructors of the FileStream class and the same exception is thrown. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Why is the compiler flagging this variable as unassigned?
    ... And you're right about the FileStream as well. ... suppressing the original error? ... include the original Exception in the Exception stack? ... >> I broke this up into two try/catch blocks. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem with FileStream - FileNotFoundException
    ... I have the following problem with FileStream. ... User on which application is running has full permision to the destination folder. ... I've cheked other constructors of the FileStream class and the same exception is thrown. ... the other computer in the same domain (Active Directory is in use). ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: throwing exception from constructor
    ... appropriate arguments to the FileStream constructor. ... line is that stream can be used to read/write data in the foo.txt file. ... a poor design choice because a constructor that throws an IOException ... Using the static factory method approach it would still be impossible ...
    (microsoft.public.dotnet.languages.csharp)

Loading