#include <NSXException.h>
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. | |
|
|
Default constructor.
Definition at line 219 of file NSXException.h. |
|
|
Destructor raises an NSException if it's been "armed".
Definition at line 223 of file NSXException.h. |
|
|
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(). |
|
|
Stores away a pointer to the ObjC NSException for raising in the destructor.
Definition at line 229 of file NSXException.h. |
1.2.17