Board index » delphi » raise exception question...

raise exception question...

Hello,
Next question maybe silly but..

Do I have to "free" something after
Raise Exception.Create('bla bla');

 

Re:raise exception question...


You should free any objects or resources you have created within the section
of code relating to the exception.  A try finally handler generally does it.
But you must free anything you created in the same block (logically or
physically) that would get freed afterwards had the exception not occured...

HTH

--
Nicholas Robinson
Senior Software Engineer
Delta Data Capture

Quote
Zarko Gajic wrote in message <6tlq5m$...@as041.tel.hr>...
>Hello,
>Next question maybe silly but..

>Do I have to "free" something after
>Raise Exception.Create('bla bla');

Re:raise exception question...


On Tue, 15 Sep 1998 15:05:00 +0100, "Nr" <n...@nrobin.demon.co.uk>
wrote:

Quote
>You should free any objects or resources you have created within the section
>of code relating to the exception.  A try finally handler generally does it.
>But you must free anything you created in the same block (logically or
>physically) that would get freed afterwards had the exception not occured...

Well, that's not entirely true.  If you study the Delphi help files on
EException class, you'll find that after you handle an exception,
Delphi will AUTOMATICALLY free the object for you.

If you DO feel the need to free it, set it to NIL afterwards to avoid
freeing it twice.

Quote

>Zarko Gajic wrote in message <6tlq5m$...@as041.tel.hr>...
>>Hello,
>>Next question maybe silly but..

>>Do I have to "free" something after
>>Raise Exception.Create('bla bla');

Re:raise exception question...


In article <6tlq5m$...@as041.tel.hr>,
  "Zarko Gajic" <gza...@sf.hr> wrote:

Quote
> Hello,
> Next question maybe silly but..

> Do I have to "free" something after
> Raise Exception.Create('bla bla');

      If you're wondering whether you need to free the
exception object you just created, no you don't.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum

Re:raise exception question...


Tony,

What I mean below is that the try finally would be used to trap the
exception so that the calling block can free anything, such as graphics
resources etc.  Freeing the actual exception is not required as it
internally frees, otherwise you would need to trap each exception you create
and free it - which is not viable due to the architecture of the Exception
mechanism.  After the exception, the code jumps back to the very first try
exception handler (if there is one).  Otherwise the exception gets raised
and each try finally on the stack is called.

I admit I think I had misunderstood the originaly question a little ...I
read the question litterally, and thus spoke about freeing the resources
created in the block and calling blocks - which you **must** do.

Regards

--
Nicholas Robinson
Senior Software Engineer
Delta Data Capture

Quote
Tony Maro wrote in message <35fe8d04.521704...@news.hiwaay.net>...
>On Tue, 15 Sep 1998 15:05:00 +0100, "Nr" <n...@nrobin.demon.co.uk>
>wrote:

>>You should free any objects or resources you have created within the
section
>>of code relating to the exception.  A try finally handler generally does
it.
>>But you must free anything you created in the same block (logically or
>>physically) that would get freed afterwards had the exception not
occured...

>Well, that's not entirely true.  If you study the Delphi help files on
>EException class, you'll find that after you handle an exception,
>Delphi will AUTOMATICALLY free the object for you.

>If you DO feel the need to free it, set it to NIL afterwards to avoid
>freeing it twice.

>>Zarko Gajic wrote in message <6tlq5m$...@as041.tel.hr>...
>>>Hello,
>>>Next question maybe silly but..

>>>Do I have to "free" something after
>>>Raise Exception.Create('bla bla');

Re:raise exception question...


In article <905868061.22705.0.nnrp-01.9e983...@news.demon.co.uk>, "Nr"

Quote
<n...@nrobin.demon.co.uk> writes:
>You should free any objects or resources you have created within the section
>of code relating to the exception.  A try finally handler generally does it.
>But you must free anything you created in the same block (logically or
>physically) that would get freed afterwards had the exception not occured...

>HTH

       I keep wondering what happens if a 'Create' goes wrong. If it screws up
half way through, how do you handle it, try again? The program won't work
without it otherwise you wouldn't be creating it, so what do you do? Re-start
the program???

Gordon

_______________
http://members.aol.com/gwhit41980/

Other Threads