Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: Andre Kaufmann <andre.kaufmann_re_move_@xxxxxxxxxxx>
- Date: Mon, 11 Jun 2007 19:58:42 +0200
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
.
- References:
- already used in a 'child' scope to denote something else
- From: valentin tihomirov
- Re: already used in a 'child' scope to denote something else
- From: Jon Skeet [C# MVP]
- Go ahead. Stop programming. This ensures you from any mistakes.
- From: valentin tihomirov
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: Göran Andersson
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: valentin tihomirov
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: Jon Skeet [C# MVP]
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: valentin tihomirov
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: Jon Skeet [C# MVP]
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: valentin tihomirov
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: Jon Skeet [C# MVP]
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: valentin tihomirov
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: Jon Skeet [C# MVP]
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: valentin tihomirov
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: Andre Kaufmann
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: valentin tihomirov
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: Andre Kaufmann
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: valentin tihomirov
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: Andre Kaufmann
- Re: Go ahead. Stop programming. This ensures you from any mistakes.
- From: valentin tihomirov
- already used in a 'child' scope to denote something else
- Prev by Date: Re: Newbie: API function call with array pointer as argument
- Next by Date: Re: Model Dialog box causes another application to get focus
- Previous by thread: Re: Go ahead. Stop programming. This ensures you from any mistakes.
- Next by thread: Re: Go ahead. Stop programming. This ensures you from any mistakes.
- Index(es):
Relevant Pages
|