4.1. Assert_exit() Macro
Assert_exit () macro serves the same
functionality as assert() function of a standard
C library.
#include <assa/Assert.h>
#define Assert_exit (a_)
|
If expression a_ is
false,
error message is written to the application log file, and process
gets SIGHUP which triggers graceful exit.
For example, I might want to test some critical pre-condition
before proceeding with a function call, and if condition fails,
write an error message to the log file and kill the process:
229: int IO_Handler::handle_read (int fd_)
230: {
231: // Test precondition
232:
233: Assert_exit (fd_ == m_peerStream->getHandler ());
234:
235: // proceed with functions execution ...
236: }
|
If my condition were to fail, an error message would
appear in the log file:
Assert Aborted False Expression!
Error on line 233 in file IO_Handler.cpp
|