[fpc-pascal] Exception withing exception handling

Sven Barth pascaldragon at googlemail.com
Sat Feb 18 15:45:17 CET 2012


Am 18.02.2012 07:05 schrieb "Chad Berchek" <ad100 at vobarian.com>:
>
> On 2/17/2012 2:26 PM, Sven Barth wrote:
>>
>> On 17.02.2012 18:36, Jorge Aldo G. de F. Junior wrote:
>
>
>>> so i am inclined to think that exceptions arent supposed to live much
>>> longer after their corresponding try except handling block.
>>>
>>> is that true ? actually, how are exceptions raised ? can i reraise one ?
>>
>>
>> To make things short: yes, that is true. Exceptions are freed after
>> either a except handler has handled it without reraising or after the
>> "unhandled exception" handler has taken control (though in the last case
>> it could be that the exception isn't freed, because the program is
>> simply terminated...).
>
>
> The AcquireExceptionObject function should be able to overcome this
problem. It is designed to "acquire" a reference to the exception object so
you sort of "own" it (actually it's reference counted; you own one
refcount) and it won't be automatically freed after the except block. Be
sure, then, in the destructor of Trowcolexception, to release the nested
exception object.
>
> http://www.freepascal.org/docs-html/rtl/system/acquireexceptionobject.html
>
> http://www.freepascal.org/docs-html/rtl/system/releaseexceptionobject.html

This is one of those moments where I need to aknowledge that even I never
stop learning ;)

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20120218/c99097fa/attachment.html>


More information about the fpc-pascal mailing list