Listing 2: Catching and rethrowing exceptions.
#include<iostream>
#include "ELF_LogManager.h"
#include "ELF_Properties.h"
DEFINE_EXCEPTION( LowestException ) ;
DEFINE_EXCEPTION( HighestException ) ;
ELF_FUNCT_DEF( void lowAbstraction1() throw( Exception ) ) {
THROW_EXCEPTION( LowestException, "A low level exception" ) ;
}
ELF_FUNCT_DEF_END
ELF_FUNCT_DEF( void highAbstractionM4() throw( Exception ) ) {
try {
lowAbstraction1() ;
}
catch( Exception &e ) {
THROW_NESTD_EXCPTN( HighestException,
"A high level exception", e ) ;
}
}
ELF_FUNCT_DEF_END
ELF_FUNCT_DEF( void highAbstractionM3() throw( Exception ) ) {
highAbstractionM4() ;
}
ELF_FUNCT_DEF_END
ELF_FUNCT_DEF( void highAbstractionM2() throw( Exception ) ) {
highAbstractionM3() ;
}
ELF_FUNCT_DEF_END
ELF_FUNCT_DEF( void highAbstractionM1() throw( Exception ) ) {
WARNG_LOG( "just a test warning" ) ;
DEBUG_LOG( "just a test debug" ) ;
ERROR_LOG( "just a test error" ) ;
AUDIT_LOG( "just a test audit" ) ;
CRIT_LOG( "just a test critical" ) ;
highAbstractionM2();
}
ELF_FUNCT_DEF_END
int main() {
try {
appConfig.initialize( "test.cfg" ) ;
logManager.initialize( LogManager::FILEBASED ) ;
//logManager.addLogWriter( LogManager::TCPBASED ) ;
//logManager.addLogWriter( LogManager::UDPBASED ) ;
highAbstractionM1() ;
}
catch( Exception &e ) {
cerr<<e<<endl ;
}
return 0 ;
}
output produced to console( cerr ):
=============== EXCEPTION INFO BEGIN ======================
WHAT : HighestException
REASON : A high level exception
METHOD: void highAbstractionM4() throw( Exception )(main.C:20)
called by void highAbstractionM3() throw( Exception )
called by void highAbstractionM2() throw( Exception )
called by void highAbstractionM1() throw( Exception )
NESTED EXCEPTION :
WHAT : LowestException
REASON : A low level exception
METHOD : void lowAbstraction1() throw( Exception )(main.C:11)
=============== EXCEPTION INFO END ========================
Part of output produced in function call trace file:
METHOD:void highAbstractionM4() throw( Exception ):ENTRY |
THREAD ID = 1024 |PID = 8352 | TIME= 09/22/2002:15-28-14
METHOD:void lowAbstraction1() throw( Exception ):ENTRY |
THREAD ID = 1024 |PID = 8352 | TIME= 09/22/2002:15-28-14
METHOD:void lowAbstraction1() throw( Exception ):EXIT |
THREAD ID = 1024 |PID = 8352 | TIME= 09/22/2002:15-28-14
METHOD:void highAbstractionM4() throw( Exception ):EXIT |
THREAD ID = 1024 |PID = 8352 | TIME= 09/22/2002:15-28-14
Output produced in the error log file ( Similar output is
produced to warning, debug, audit and critical log files ):
--ERROR MSG BEGIN--void highAbstractionM1() throw( Exception )
just a test error
--ERROR MSG END-- |THREAD ID = 1024 |PID = 8352 | TIME= 09/22/2002:15-28-14