1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
// ----------------------------------------------------------------------
//
// testzmex.cc - test whether namespaces work out.
//
// History:
// 04/13/01 mf wrote
//
//
// usage: Place into src and test makefile
// override CPPFLAGS += -DZM_USE_NAMESPACES
// and build.
// ----------------------------------------------------------------------
#include <string>
using std::string;
#include "CLHEP/Cast/itos.h"
#include "CLHEP/Exceptions/ZMthrow.h"
#include "CLHEP/Exceptions/ZMexception.h"
#include "CLHEP/Exceptions/ZMerrno.h"
// remove the above line to test with namespace on.
// ----------
// Define exception classes and default behaviors:
// ----------
ZMexStandardDefinition( zmex::ZMexception, ZMxTest );
zmex::ZMexClassInfo ZMxTest::_classInfo(
"ZMxTest", "Test", zmex::ZMexSEVERE );
// ----------
// Define output formats, etc
// ----------
const string QUOTE = "\"";
const string NEWLINE1 = "\n";
const string NEWLINE2 = "\n\n";
void display( const zmex::ZMexception * ex ) {
zmex::ZMlogger().emit( NEWLINE1
+ ex->name() + ": " + QUOTE + ex->message() + QUOTE + NEWLINE1
+ " " + (ex->wasThrown() ? "thrown" : "ignored")
+ " by " + ex->handlerUsed() + "()" + NEWLINE1
);
}
int main() {
// ----------
// Begin testing, check out basic logger:
// ----------
zmex::ZMlogger().emit( NEWLINE1 );
zmex::ZMlogger().emit( "---------- Begin testing: ----------\n" );
zmex::ZMlogger().emit( NEWLINE1 );
zmex::ZMlogger().emit( "This message checks out basic logger behavior\n" );
ZMthrow( ZMxTest( "Testing exception behavior" ) );
// ----------
// Done, go home
// ----------
return 0;
} // main()
|