Re: Go ahead. Stop programming. This ensures you from any mistakes.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



valentin tihomirov wrote:
> [...]
The problem is - if you read the code you can't see what the macro is doing. How do I know if it leaves the function ?

How do you know that 'throw e' leaves the function?

Well if you don't catch it somewhere you will now ;-).
A return value can be silently left unhandled.

[...]
Oh dear, using does the job of finally:

Don't think so. You don't have to explicitly write and think about adding a Dispose call.

>[...]
I'm not sure that the 'using' brings much advantage here. The 'finally' is more capable as it is not fixed to IDisposable clean up method.

You could create an object which gets a reference to the resources to handle which it releases in the Dispose method.
Mimics C++ RAII (somewhat).

[...]
My data tells me that there are no exceptions is C++ (excepting proprietary solutions which lack try-finally, and are useless therefore). The issue is not whether I have to care about everything in C/C++. The question is how can I minimize the effort on controlling dynamically allocated resoureses.

C++ works totally different - there is "no finally needed".

[...]
I may mistake but Delphi invokes destructors automatially as well on

Yes, AFAIK.

partially created objects. But it is silly to initialize-flag every resourse to be allocated and then cheking the frag before free. It is more rational to figure out the level of object construction and start destroying unconditionally from that point.

Well as I already wrote, in C++ this initialize list is handled by the compiler automatically. In C# I miss RAII somewhat, though I can live with using blocks.

>[...]
I just claimed that you can do it:

Object o1 = null;
Object o2 = null;

try
{
.....
}
catch(System.Exception)
{
o1.Dispose(); // destroy - meaning freeing resources
o2.Dispose(); //
}

Won't you get "NullPointerException"? The majority suggests to perform

Sorry yes my fault. You have to check it before. Forgot the check.

[...]

But commonly in C# you don't have to care about, if the objects don't hold any resources which immediately have to be freed.

GC cares about nothing besidies memory.

As I said - if resources don't have to freed immediately.
You can release resources in a finalizer, but that may be (commonly) too late - if it's ever is called.


[...]

Andre
.



Relevant Pages

  • Re: GC performance - GC fragility
    ... I rather prefer to know the details, but having not to care about them during coding. ... which does nothing more than allocating memory in an endless loop doesn't eat all the systems memory. ... For these kind of resources even in a GC environment reference counting is needed. ... If my application has a significant performance decrease, when using .NET compare to the native implementation then yes, I wouldn't let the customer pay for it. ...
    (borland.public.delphi.non-technical)
  • Re: OT - American Red Cross was OT - Katrina - Military Swings Into Action
    ... What I've been saying is that we are not taking care of our own country's needs. ... We have people here with no healthcare and we are closing hospitals daily, yet we are building brand new state-of-the art ones in Iraq. ... I believe that my concern for America first and foremost is patriotic and a strong America will enable us to be a stronger world power. ... We are weakening ourselves by misdirecting our resources and part of those resources are our young ...
    (rec.outdoors.rv-travel)
  • Re: What Happens?
    ... home and Medicaid would pay the bill if the person's resources were ... the person would not be just left to die ... through speech of writing, and had resources to pay for care, they ...
    (soc.retirement)
  • Re: What Happens?
    ... home and Medicaid would pay the bill if the person's resources were ... the person would not be just left to die ... through speech of writing, and had resources to pay for care, they ...
    (soc.retirement)
  • Re: What Happens?
    ... home and Medicaid would pay the bill if the person's resources were ... the person would not be just left to die ... through speech of writing, and had resources to pay for care, they ...
    (soc.retirement)