File: exctestNothrow.cc

package info (click to toggle)
clhep 2.1.4.1%2Bdfsg-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,012 kB
  • sloc: cpp: 50,094; sh: 6,694; makefile: 2,694; perl: 28
file content (94 lines) | stat: -rwxr-xr-x 3,071 bytes parent folder | download | duplicates (5)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// This program tests the DEFECT_NO_EXCEPTIONS version of the Exceptions package:
//   12-Dec-2001  WEB  Avoid signed/unsigned comparison warnings

#ifndef DEFECT_NO_EXCEPTIONS
  #define DEFECT_NO_EXCEPTIONS 1
#endif


#include "CLHEP/Exceptions/ZMthrow.h"
#include "CLHEP/Exceptions/ZMexception.h"
#include "CLHEP/Exceptions/ZMerrno.h"
using namespace zmex;

#include <fstream>
using namespace std;


// We try to have this test program test several cases, including
// several actual throws, so we assume that the DEFECT_NO_EXCEPTIONS version of
// the ZMthrow macro will use exit() or abort() and so override
// those behaviors in order to keep going for multiple testing herein:
#include <stdio.h>
#define exit( x ) printf( "this is an actual exit\n", x );
#define abort(  ) printf( "this is an actual abort\n"  );


ZMexStandardDefinition( ZMexception, ZMxTop );
ZMexClassInfo ZMxTop::_classInfo( "ZMxTop", "HepTuple" );

ZMexStandardDefinition( ZMxTop, ZMxHepTuple );
ZMexClassInfo ZMxHepTuple::_classInfo( "ZMxHeptuple", "HepTuple" );

ZMexStandardDefinition( ZMexception, ZMxTop2 );
ZMexClassInfo ZMxTop2::_classInfo( "ZMxTop2", "Other Top Exception" );

ZMexStandardDefinition( ZMxTop2, ZMxHepTuple2 );
ZMexClassInfo ZMxHepTuple2::_classInfo( "ZMxHepTuple2", "Other HepTuple" );

ZMexStandardDefinition( ZMxHepTuple2, ZMxColumn );
ZMexClassInfo ZMxColumn::_classInfo( "ZMxColumn", "Column excep" );


int main (  ) {

  ZMxTop::setHandler( ZMexIgnoreAlways(  ) );
  ZMxHepTuple::setHandler( ZMexThrowAlways(  ) );

  printf( "Try to ignore a ZMxTop with msg -top-\n" );
  ZMthrow( ZMxTop( "top" ) );
  printf( "Try to throw a ZMxHepTuple with msg -bottom-\n" );
  ZMthrow( ZMxHepTuple( "bottom" ) );

  printf( "Try to throw a top exception with a ZMhParentHandler\n" );
  ZMthrow( ZMxTop2( "top2" ) );

  printf( "Try to throw a ZMxColumn\n" );
  ZMthrow( ZMxColumn( "a column error" ) );

  ZMxHepTuple2::setHandler( ZMexIgnoreNextN( 3 ) );

  std::ofstream logfile( "exception.report" );
  ZMxHepTuple2::setLogger( ZMexLogAlways( logfile ) );

  printf( "Try to throw a ZMxTop2\n" );
  ZMthrow( ZMxTop2( "top2" ) );

  printf( "Try to ignore a ZMxHepTuple2\n" );
  ZMthrow( ZMxHepTuple2( "a heptuple error" ) );

  //ZMxColumn::logNMore(  4  );
  printf( "Try to ignore a ZMxColumn\n" );
  ZMthrow( ZMxColumn( "2 column error" ) );
  printf( "Try to ignore a ZMxColumn\n" );
  ZMthrow( ZMxColumn( "3 column error" ) );
  printf( "Try to throw a ZMxColumn\n" );
  ZMthrow( ZMxColumn( "4 column error" ) );
  printf( "Try to throw a ZMxColumn\n" );
  ZMthrow( ZMxColumn( "5 column error" ) );

  std::cout << "logged the following exceptions\n";
  unsigned int s;
  for ( s = 0; s <  ZMerrno.size(  ); s++  ) {
    std::cout << ZMerrno.get( s )->name(  ) << " : " <<
		ZMerrno.get( s )->message(  ) << std::endl;
  }
  std::cout << "Reset the length of ZMerrno to 4\n";
  ZMerrno.setMax( 4 );
  for ( s = 0; s <  ZMerrno.size(  ); s++  ) {
    std::cout << ZMerrno.get( s )->name(  ) << " : " <<
		ZMerrno.get( s )->message(  ) << std::endl;
  }

  return 0;
}