File: testThrowFrom.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 (74 lines) | stat: -rwxr-xr-x 2,055 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
// ----------------------------------------------------------------------
//
// testThrowFrom.cc - test the ZMthrow_from() method,
//                    and the ZMexValidationStyle behavior,
//                    and setName, setSeverity, setFacility.
//
// History:
//   10-Apr-2001  mf   Initial draft testing just ZMthrow_from()
//   11-Apr-2001  mf   Test the other enhancements.
//   12-Jun-2002  web  Insert conditional try-catch to allow testing in
//     presence of true exceptions
//
// ----------------------------------------------------------------------

#include "CLHEP/Exceptions/ZMthrow.h"
#include "CLHEP/Exceptions/ZMexception.h"

using namespace zmex;

ZMexStandardDefinition( ZMexception, ZMxTest );
ZMexClassInfo ZMxTest::_classInfo(
  "ZMxTest", "Test", ZMexSEVERE );

int main()  {

//  std::cout << "starting...\n";


// Not:      ZMexception::setHandler( ZMexIgnoreAlways() ) ;
// Instead:
  ZMxTest::setSeverity( ZMexWARNING ); // Which should not abort

  ZMexception::setLogger( ZMexValidationStyle(std::cout) ) ;

//  std::cout << "throwing...\n";

  ZMthrow_from( ZMxTest("Artificial Exception"), 1000,
                "directory/subdirectory/fictitious.file" );

  ZMthrow_from( ZMxTest("Artificial backslash Exception"), 4000,
                "directory/subdirectory\\fictitious.file" );

  ZMthrow_from( ZMxTest("Artificial no slash Exception"), 4000,
                "fictitious.file" );

  ZMthrow( ZMxTest("Normal exception") );

  ZMxTest::setName("MyExName");
  ZMthrow( ZMxTest("Exception with new name") );

  ZMxTest::setFacility("newFacility");
  ZMthrow( ZMxTest("Exception from new facility") );

  // -------------
  // Done, go home
  // -------------

  ZMexception::setLogger( ZMexLogAlways(std::cout) ) ;

  ZMxTest::setSeverity( ZMexERROR ); // Which should not abort
#ifndef DEFECT_NO_EXCEPTIONS
  try {
#endif
    ZMthrow( ZMxTest("Ordinary Error") );
#ifndef DEFECT_NO_EXCEPTIONS
  }
  catch( ZMexception & e )  {
    std::cerr << "Caught: " << e.name() << "\n";
  }
#endif

  return 0;

}  // main()