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

NSXException.h File Reference

#include <Cocoa/Cocoa.h>
#include <exception>
#include <typeinfo>

Go to the source code of this file.

Compounds

class  AutoNSExceptionHandler
 Scope-aware C++ wrapper for NSException's _NSHandler2. More...

class  NSXException
 Main class & C++ wrapper object for ObjC NSException objects. More...

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


Defines

#define NSX_THROW
 Better version of NSX_DURING/NSX_HANDLER/NSX_ENDHANDLER if you don't need a custom handler (which you usually don't if you're using stack-based objects).

#define NSX_ENDTHROW
 Counterpart to NSX_THROW.

#define NSX_RAISE
 NSX_THROW's evil twin.

#define NSX_ENDRAISE
 Counterpart to NSX_RAISE.

#define ThrowNSX(CODE)
 Wraps a line of ObjC code in a handler (which handles raised ObjC exceptions, morphs them into C++ exceptions and throws them).

#define RaiseNSX(CODE)
 Wraps a line of C++ code in a try/catch block (which catches thrown C++ exceptions, morphs them into ObjC exceptions and raises them via NSXRaisingDestructor).

#define NSX_DURING
 Drop-in replacement for NS_DURING, except uses AutoNSExceptionHandler and thus doesn't require the NS_[VOID|VALUE]RETURN hack.

#define NSX_HANDLER
 Denotes beginning of handler block started by NSX_DURING.

#define NSX_ENDHANDLER
 Denotes ending of handler block started by NSX_DURING.


Define Documentation

#define NSX_DURING
 

Value:

{                                                                   \
        AutoNSExceptionHandler  handler_;                               \
        if( !_NSSETJMP( handler_._state, 0 ) ) {
Drop-in replacement for NS_DURING, except uses AutoNSExceptionHandler and thus doesn't require the NS_[VOID|VALUE]RETURN hack.

See also:
NSX_HANDLER NSX_ENDHANDLER

Definition at line 436 of file NSXException.h.

#define NSX_ENDHANDLER
 

Value:

localException = localException;                            \
        }                                                               \
    }
Denotes ending of handler block started by NSX_DURING.

See also:
NSX_DURING NSX_HANDLER

Definition at line 459 of file NSXException.h.

#define NSX_ENDRAISE
 

Value:

} catch( const std::exception *x ) {    \
            raisingDestructor.arm( x );         \
        }                                       \
    }
Counterpart to NSX_RAISE.

See also:
NSX_RAISE

Definition at line 338 of file NSXException.h.

#define NSX_ENDTHROW
 

Value:

} else {                                                \
            NSXException::Throw( handler_.localException() );   \
        }                                                       \
    }
Counterpart to NSX_THROW.

See also:
NSX_THROW

Definition at line 296 of file NSXException.h.

#define NSX_HANDLER
 

Value:

} else {                                                        \
            NSException *localException = handler_.localException();
Denotes beginning of handler block started by NSX_DURING.

See also:
NSX_DURING NSX_ENDHANDLER

Definition at line 448 of file NSXException.h.

#define NSX_RAISE
 

Value:

{                                               \
        NSXRaisingDestructor raisingDestructor;     \
        try {
NSX_THROW's evil twin.

Automatically catches thrown C++ exception pointers, morphs them into ObjC exception objects and raises them via NSXRaisingDestructor. Use it like this:

    - (void)foo() {
        [obj1 msg1];
        [obj2 msg2];
        
        NSX_RAISE
            // This will always be destructed, even if an exception is raised below.
            auto_ptr<BigStruct> bsOne = new BigStruct();
            bsOne->possiblyThrowingMethod();
        NSX_ENDRAISE
        
        [obj3 msg3];
    }

See also:
NSX_ENDTHROW

Definition at line 326 of file NSXException.h.

#define NSX_THROW
 

Value:

{                                               \
        AutoNSExceptionHandler  handler_;           \
        if( !_NSSETJMP( handler_._state, 0 ) ) {
Better version of NSX_DURING/NSX_HANDLER/NSX_ENDHANDLER if you don't need a custom handler (which you usually don't if you're using stack-based objects).

Automatically handles raised ObjC exceptions, morphs them into C++ exceptions and throws them. Use it like this:

    void foo() {
        try {
            // This will always be destructed, even if an exception is raised below.
            auto_ptr<BigStruct> bsOne = new BigStruct();
            
            NSX_THROW
                [obj1 msg1];
                [obj2 msg2];
                
                safeCFunction();
                bsOne->possiblyThrowingMethod();
                
                [obj3 msg3];
            NSX_ENDTHROW
            
            // The following is never constructed if exception is raised above.
            auto_ptr<BigStruct> bsTwo = new BigStruct();
        } catch( const std::exception *x ) {
            NSXException::Raise( x );
        }
    }

See also:
NSX_ENDTHROW

Definition at line 284 of file NSXException.h.

#define RaiseNSX CODE   
 

Value:

{                                           \
        NSXRaisingDestructor raisingDestructor; \
        try {                                   \
            CODE;                               \
        } catch( const std::exception *x ) {    \
            raisingDestructor.arm( x );         \
        }                                       \
    }
Wraps a line of C++ code in a try/catch block (which catches thrown C++ exceptions, morphs them into ObjC exceptions and raises them via NSXRaisingDestructor).

While easy to use, it bloats produced code, so use it sparingly. (Use NSX_RAISE/NSX_ENDRAISE for long C++ code runs.)

Use it like this:

    - (void)foo() {
        [obj1 msg1];
        [obj2 msg2];
        
        RaiseNSX( int result = cppObject->possiblyThrowingMethod() );
        
        [obj3 msg3];
    }

See also:
NSX_RAISE

Definition at line 410 of file NSXException.h.

#define ThrowNSX CODE   
 

Value:

{                                                           \
        AutoNSExceptionHandler  handler_;                       \
        if( !_NSSETJMP( handler_._state, 0 ) ) {                \
            CODE;                                               \
        } else {                                                \
            NSXException::Throw( handler_.localException() );   \
        }                                                       \
    }
Wraps a line of ObjC code in a handler (which handles raised ObjC exceptions, morphs them into C++ exceptions and throws them).

While easy to use, it bloats produced code, so use it sparingly. (Use NSX_THROW/NSX_ENDTHROW for long ObjC code runs.)

Use it like this:

    void foo() {
        try {
            // This will always be destructed, even if an exception is raised below.
            auto_ptr<BigStruct> bsOne = new BigStruct();
            
            ThrowNSX( int result = [obj1 msg1] );
            bsOne->possiblyThrowingMethod( result );
        } catch( const std::exception *x ) {
            NSXException::Raise( x );
        }
    }

See also:
NSX_THROW

Definition at line 377 of file NSXException.h.


Generated on Wed Mar 5 09:57:47 2003 for TempFile by doxygen1.2.17