Classes | Functions | Variables
Exception_t.cc File Reference
#include "cetlib_except/exception.h"
#include <cassert>
#include <iomanip>
#include <iostream>
#include <string>

Go to the source code of this file.

Classes

struct  Thing
 

Functions

std::ostream & operator<< (std::ostream &os, const Thing &t)
 
void func3 ()
 
void func2 ()
 
void func1 ()
 
int main ()
 

Variables

const char expected []
 
const char * correct [] = {"InfiniteLoop", "DataCorrupt"}
 

Function Documentation

void func1 ( )

Test function 1.

Returns
A integer.

Definition at line 79 of file Exception_t.cc.

80 {
81  try {
82  func2();
83  }
84  catch (cet::exception& e) {
85  throw cet::exception("InfiniteLoop", "In func1", e) << "Gave up";
86  }
87 }
const double e
void func2()
Definition: Exception_t.cc:73
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
int main ( void  )

Definition at line 116 of file Exception_t.cc.

117 {
118  try {
119  func1();
120  }
121  catch (cet::exception& e) {
122  std::cerr << "*** main caught Exception, output is ***\n"
123  << "(" << e.explain_self() << ")\n"
124  << "*** After exception output ***" << std::endl;
125 
126  if (e.explain_self() != expected) {
127  std::cerr << "not right answer\n(" << expected << ")\n" << std::endl;
128  abort();
129  }
130 
131  std::cerr << "\nCategory name list:\n";
132 
133  cet::exception::CategoryList::const_iterator i(e.history().begin()),
134  b(e.history().end());
135 
136  // if(e.history().size() !=2) abort();
137  assert(e.history().size() == 2);
138 
139  for (int j = 0; i != b; ++i, ++j) {
140  std::cout << " " << *i << "\n";
141  if (*i != correct[j]) {
142  std::cerr << "bad category " << *i << std::endl;
143  abort();
144  }
145  }
146  }
147  return 0;
148 }
const char expected[]
Definition: Exception_t.cc:22
intermediate_table::const_iterator const_iterator
const double e
const char * correct[]
Definition: Exception_t.cc:113
void func1()
Definition: Exception_t.cc:79
static bool * b
Definition: config.cpp:1043
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
std::ostream& operator<< ( std::ostream &  os,
const Thing t 
)

Definition at line 16 of file Exception_t.cc.

17 {
18  os << "Thing(" << t.x << ")";
19  return os;
20 }
int x
Definition: Exception_t.cc:12

Variable Documentation

const char* correct[] = {"InfiniteLoop", "DataCorrupt"}

Definition at line 113 of file Exception_t.cc.

const char expected[]
Initial value:
= "---- InfiniteLoop BEGIN\n"
" In func1\n"
" ---- DataCorrupt BEGIN\n"
" This is just a test: \n"
" double: 1.11111\n"
" float: 2.22222\n"
" uint: 75\n"
" string: a string\n"
" char*: a nonconst pointer\n"
" char[]: a c-style array\n"
" Thing: Thing(4)\n"
" \n"
" double: 1.111110e+00\n"
" float: 2.22e+00\n"
" char*: ..a nonconst pointer\n"
" \n"
" ---- DataCorrupt END\n"
" Gave up\n"
"---- InfiniteLoop END\n"

Definition at line 22 of file Exception_t.cc.