[fpc-pascal] methods of an object to create others objects
md at delfire.net
Wed Jul 7 03:14:57 CEST 2010
On Tue, Jul 6, 2010 at 7:14 PM, Andrew Brunner
<andrew.t.brunner at gmail.com> wrote:
> On Tue, Jul 6, 2010 at 5:09 PM, Graeme Geldenhuys
> <graemeg.lists at gmail.com> wrote:
>> Even with a try..except, if you call MyObj.Free and it causes an
>> exception, you are screwed either way and it will always cause a
>> memory leak. Best is no notify the user some how, or crash out of the
>> program, or fire the programmer for not writing enough unit tests. :)
> No, if the nesting is done properly you could guarantee that Obj2.Free
> would be called even if Obj1.Free failed with some exception. And
> further, nested exception handling offers safeguarding against such
> memory leaks during destruction if done properly. To me this is the
> difference between good software and great software... How well it
> handles exceptions.
Okay, you're right. Nesting exception handling is the only way to
avoid memory from leaking, in these cases.
And now? Your program failed (e.g.) using Free method... you assured
there is no memory leaking (using nesting exceptions), but this is a
totally _unexpected_ exception!
IMHO the program should be aborted, the user is notified, log this
error... start again.
If the program is a web app, you can't abort immediately (no?)... but
you'll do it sometime ;-)
I'm more concerned with programming errors that can not see
immediately, such as forgetting to free some object. For me, an
Exception is an exception! I did not expect and I need do something
(if the program does not have its own treatment for what occurred).
More information about the fpc-pascal