sources/TPGPException.h

//------------------------------------------------------------------------------------
//
//  TPGPException  - PGP Exception Class Object
// 
// Apple Macintosh Developer Technical Support
// Written by:  Vinnie Moscaritolo
//
//  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
//
// You may incorporate this sample code into your applications without
// restriction, though the sample code has been provided "AS IS" and the
// responsibility for its operation is 100% yours.  However, what you are
// not permitted to do is to redistribute the source as "DSC Sample Code"
// after having made changes. If you're going to re-distribute the source,
// we require that you make it clear in the source that the code was
// descended from Apple Sample Code, but that you've made changes.
// 
 
 
#pragma once 
 
#include "pgpErrors.h"
 
 
// ______________________________________________________________________________
// EXCEPTION CLASSES
 
class TPGPException 
{
public:
    TPGPException(const PGPError theError) :
                    fMessage("NO MESSAGE SPECIFIED"), 
                    fError(theError), 
                    fFileName("NO FILE SPECIFIED"), 
                    fLineNumber(0L) 
                    {};
 
    TPGPException(const char *theMessage, const PGPError theError) :
                    fMessage(theMessage), 
                    fError(theError), 
                    fFileName("NO FILE SPECIFIED"), 
                    fLineNumber(0L) 
                    {};
                    
    TPGPException(const char *theMessage, const PGPError theError, const char *theFileName, const long theLineNumber) :
                    fMessage(theMessage), 
                    fError(theError), 
                    fFileName(theFileName), 
                    fLineNumber(theLineNumber) 
                    {};
                    
    const char*     GetExceptionMessage(void)   { return fMessage;};
    const PGPError  GetExceptionErr(void)       { return fError;};
    const char*     GetExceptionFile(void)      { return fFileName;};
    const long      GetExceptionLine(void)      { return fLineNumber;};
    
protected:
    const PGPError  fError;
    const char*     fMessage;
    const char*     fFileName;
    const long      fLineNumber;
};
 
 
//------------------------------------------------------------------------------------
#pragma mark Useful Macros
//------------------------------------------------------------------------------------
 
 
#define ThrowPGPIfNil( _val_ )                                      \
        if ( (_val_) == nil )                                       \
            throw TPGPException( "UNEXPECTED NIL RETURNED" ,0 , __FILE__, __LINE__)  
 
#define ThrowPGPIfNotNil( _val_ )                                               \
        if ( (_val_) != nil )                                                   \
            throw TPGPException( "EXPECTED NIL" ,0 , __FILE__, __LINE__) 
 
#define ThrowPGPIfTrue( _val_ )                                     \
        if ( (_val_) )                                      \
            throw TPGPException( "NO MESSAGE SPECIFIED" ,0 , __FILE__, __LINE__)     
 
#define ThrowPGPIfFalse( _val_ )                                                \
        if ( !(_val_) )                                                 \
            throw TPGPException( "NO MESSAGE SPECIFIED" ,0 , __FILE__, __LINE__) 
 
#define ThrowPGPErrIfTrue( _val_, _err_  )                                      \
        if ( (_val_) )                                      \
            throw TPGPException( "NO MESSAGE SPECIFIED" , (_err_) , __FILE__, __LINE__)  
 
#define ThrowPGPErrIfFalse( _val_, _err_  )                                     \
        if ( !(_val_) )                                     \
            throw TPGPException( "NO MESSAGE SPECIFIED" , (_err_) , __FILE__, __LINE__)  
 
 #define ThrowPGPErrIfNotNil( _val_, _err_  )                                       \
        if ( (_val_) != nil )                                                   \
            throw TPGPException( "NO MESSAGE SPECIFIED" , (_err_) , __FILE__, __LINE__)  
 
#define ThrowPGPErrIfNil( _val_, _err_  )                                       \
        if ( (_val_) == nil )                                       \
            throw TPGPException( "NO MESSAGE SPECIFIED" , (_err_) , __FILE__, __LINE__)  
 
#define ThrowIfPGPErr(_err_)                                        \
        { PGPError _temp_ = (_err_);    \
        if ( _temp_ != kPGPError_NoErr)                                         \
            throw TPGPException( "NO MESSAGE SPECIFIED",  _temp_, __FILE__, __LINE__); }
 
#define ThrowPGPErr(_err_)                                              \
            throw TPGPException( "NO MESSAGE SPECIFIED", (_err_), __FILE__, __LINE__)    
 
#define ThrowPGPMsgIfErr(_err_, _Msg_)                                      \
        if ((_err_) != kPGPError_NoErr)                                         \
            throw TPGPException( (_Msg_), (_err_), __FILE__, __LINE__)   
 
 
#define ThrowPGPErr(_err_)                                              \
            throw TPGPException( "NO MESSAGE SPECIFIED", (_err_), __FILE__, __LINE__)    
 
#define ThrowMsgIfPGPErr(_err_, _Msg_)                                      \
        { PGPError _temp_ = (_err_);    \
        if ( _temp_ != kPGPError_NoErr)                                         \
            throw TPGPException( (_Msg_), _temp_, __FILE__, __LINE__); }