Re: Try Catch Finally in MFC

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: Try Catch Finally in MFC
    ... At different stages of execution i am creating new variables. ... Handle the exception. ... In the destructor of the C++ class deallocate pointers if they are not null. ...
    (microsoft.public.vc.mfc)
  • Re: Differences in data description in programming languages
    ... That certainly is true of statics _and_ automatics. ... >>Those can happen in Cobol too, and have nothing to do with pointers. ... OO systems an exception will be passed up the process until it is ...
    (comp.lang.cobol)
  • Re: MiniDumpWriteDump
    ... I changed the structure to use pointers instead of using the types inline ... Now, when an exception occurs, and is caught my me (see sample code in same ... (Please forget my last posting's question about whether the API can access ... >>> End Sub ...
    (microsoft.public.vb.winapi)
  • Re: N1298 - try/finally for C
    ... Using a void*, or something containing a void*, gives ... Then we have a function that potentially throws an exception: ... If you mean some custom allocator, then we generally need to pass yet ... As for function pointers, and besides that throwing function pointers ...
    (comp.std.c)
  • RE: win32 heap overflow exploitation
    ... by another exception handler. ... As eEye often mentions it is possible to overwrite other locations, ... and PEB locking pointers. ... because ecx is unwritable address thus invokin exception handler. ...
    (Vuln-Dev)