Main Page   Compound List   File List   Compound Members   File Members   Related Pages  

NSXRaisingDestructor Class Reference

#include <NSXException.h>

List of all members.


Detailed Description

Usually raising an ObjC NSException invokes a longjmp out of the current function.

Unfortunately, longjmp is rather primative and knows nothing about C++, so your stack-based objects' destructors will never be called.

This class is a hack that gets around that. Declare a stack-based instance of it at the very top of your function/method. Upon destruction, hopefully after all your other stack-based objects have been destructed, it will raise an exception if it has been "armed". Use it like this:

    void foo() {
        NSXRaisingDestructor raisingDestructor;
        auto_ptr<BigStruct> bar = new BigStruct();
        try {
            ThrowNSX( [obj foo] );
        } catch( const std::exception *x ) {
            raisingDestructor.arm( x );
        }
        // bar's destructor will correctly be called here for you
        // raisingDestructor's destructor will re-raise the ObjC exeception here for you.
    }

Definition at line 216 of file NSXException.h.

Public Methods

 NSXRaisingDestructor ()
 Default constructor.

 ~NSXRaisingDestructor ()
 Destructor raises an NSException if it's been "armed".

void arm (NSException *exception)
 Stores away a pointer to the ObjC NSException for raising in the destructor.

void arm (const std::exception *exception)
 Morphs the given C++ exception to a ObjC NSException for later raising in the destructor.


Constructor & Destructor Documentation

NSXRaisingDestructor::NSXRaisingDestructor   [inline]
 

Default constructor.

Definition at line 219 of file NSXException.h.

NSXRaisingDestructor::~NSXRaisingDestructor   [inline]
 

Destructor raises an NSException if it's been "armed".

Definition at line 223 of file NSXException.h.


Member Function Documentation

void NSXRaisingDestructor::arm const std::exception *    exception [inline]
 

Morphs the given C++ exception to a ObjC NSException for later raising in the destructor.

Definition at line 235 of file NSXException.h.

References NSXException::NSExceptionForException().

void NSXRaisingDestructor::arm NSException *    exception [inline]
 

Stores away a pointer to the ObjC NSException for raising in the destructor.

Definition at line 229 of file NSXException.h.


The documentation for this class was generated from the following file:
Generated on Wed Mar 5 09:57:47 2003 for TempFile by doxygen1.2.17