Re: Try Catch Finally in MFC
- From: "nkg" <xyz@xxxxxxxxx>
- Date: Mon, 23 Jul 2007 17:13:25 -0500
thx. David / Joseph for you insight, This answered my question. Its
wonderful to discuss with you
all gurus.
"David Wilkinson" <no-reply@xxxxxxxxxxxx> wrote in message
news:%23$F2sLRzHHA.5092@xxxxxxxxxxxxxxxxxxxxxxx
slg wrote:
thx Joseph and David,
Here is the situation. At different stages of execution i am creating new
variables. In case there is an
exception i want to release them.
Combining both of your thoughts, it will be wise to
1. Wrap the pointers in a C++ class
2. Handle the exception.
3. In the destructor of the C++ class deallocate pointers if they are
not null.
slg:
I am still unsure what you are trying to do. I thought you were
deliberately throwing an exception in your own code and then catching in
the same function, because you thought this would help you with cleanup.
If this is true, I would say it is a mistake. Why don't you just return
from the function with an error code? RAII is not just to do with
exceptions, but also with early return from a function.
Also, you mention wrapping a "pointers" in a smart pointer. This might be
a good idea, but why are you using pointers at all? The correct C++ idiom
is normally "stack semantics".
Maybe you should show some code of what you are realy trying to do.
--
David Wilkinson
Visual C++ MVP
.
- References:
- Try Catch Finally in MFC
- From: slg
- Re: Try Catch Finally in MFC
- From: Joseph M . Newcomer
- Re: Try Catch Finally in MFC
- From: slg
- Re: Try Catch Finally in MFC
- From: David Wilkinson
- Try Catch Finally in MFC
- Prev by Date: Re: Bug in MFC CList?
- Next by Date: CThreadLocalObject Crash on Exit
- Previous by thread: Re: Try Catch Finally in MFC
- Next by thread: What message when deactivating dialog.
- Index(es):
Relevant Pages
|