#include <climits> #include <cwchar> #include <boost/static_assert.hpp> namespace my_conditions { BOOST_STATIC_ASSERT(sizeof(int) * CHAR_BIT >= 32); BOOST_STATIC_ASSERT(WCHAR_MIN >= 0); } // namespace my_conditions
-DNDEBUG
-option. That's why they only should be used to test against implementation errors. #include <cassert> #include <iostream> using namespace std; int iabs( int x ) { int retVal = x > 0 ? x : -x; assert( x >= 0 ); return retVal; } int main(void) { cerr << "|-3| = " << iabs( -3 ) << endl; return 0; }
throws()
will generate an empty throws clause.mm_exception
. OutOfMemory
. void *mem = malloc( 1000 ); if ( mem == NULL ) throw OutOfMemory( "mem", 1000 );
>>
- and <<
-operators. The program using the stream rather has to check for the stream's state (and may throw an exception). #include <iostream> using namespace std; int main(void) { bool b = false; if ( cin >> b ) cout << b << endl; return 0; }