TF++, Miscellaneous classes and modules in C++:

◆ main()

int main ( int  iargc,
char *  argv[] 
)

Definition at line 88 of file exceptiontest.cc.

References tfxx::cmdline::arg_no, tfxx::error::Exception::dont_report_on_construct(), EXCEPTIONTEST_VERSION, Options::noresume, tfxx::cmdline::Commandline::optset(), tfxx::error::Exception::report(), tfxx::error::Exception::report_on_construct(), Options::reportonconstruct, tfxx::error::Exception::restore_report_state(), Options::throwbase, and A::throwit().

89 {
90 
91  // define usage information
92  char usage_text[]=
93  {
95  "usage: exceptiontest [-b] [-nr] [-roc]" "\n"
96  " or: exceptiontest --help|-h" "\n"
97  };
98 
99  // define full help text
100  char help_text[]=
101  {
102  EXCEPTIONTEST_CVSID
103  "\n"
104  "-b throw base class\n"
105  "-nr do not resume\n"
106  "-roc report on construct\n"
107  };
108 
109  // define commandline options
110  using namespace tfxx::cmdline;
111  static Declare options[]=
112  {
113  // 0: print help
114  {"help",arg_no,"-"},
115  // 1: verbose mode
116  {"v",arg_no,"-"},
117  // 2: throw base class
118  {"b",arg_no,"-"},
119  // 3: no resume
120  {"nr",arg_no,"-"},
121  // 4: no resume
122  {"roc",arg_no,"-"},
123  {NULL}
124  };
125 
126  // no arguments? print usage...
127  if (iargc<1)
128  {
129  cerr << usage_text << endl;
130  exit(0);
131  }
132 
133  // collect options from commandline
134  Commandline cmdline(iargc, argv, options);
135 
136  // help requested? print full help text...
137  if (cmdline.optset(0))
138  {
139  cerr << usage_text << endl;
140  cerr << help_text << endl;
141  exit(0);
142  }
143 
144  Options opt;
145  opt.throwbase=cmdline.optset(2);
146  opt.noresume=cmdline.optset(3);
147  opt.reportonconstruct=cmdline.optset(4);
148 
149  /*
150  // dummy operation: print option settings
151  for (int iopt=0; iopt<2; iopt++)
152  {
153  cout << "option: '" << options[iopt].opt_string << "'" << endl;
154  if (cmdline.optset(iopt)) { cout << " option was set"; }
155  else { cout << "option was not set"; }
156  cout << endl;
157  cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
158  cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
159  cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
160  cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
161  cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
162  cout << " argument (bool): '";
163  if (cmdline.bool_arg(iopt))
164  { cout << "true"; } else { cout << "false"; }
165  cout << "'" << endl;
166  }
167  while (cmdline.extra()) { cout << cmdline.next() << endl; }
168 
169  // dummy operation: print rest of command line
170  while (cmdline.extra()) { cout << cmdline.next() << endl; }
171  */
172 
173  A a(opt.throwbase);
174 
175  if (opt.reportonconstruct)
176  {
178  }
179  else
180  {
182  }
183 
184  try {
185  a.throwit();
186  } catch (tfxx::error::Exception& e) {
187  cout << "caught exception" << endl;
188  e.report();
189  if (opt.noresume)
190  {
191  throw(e);
192  }
193  }
194 
195  cout << "again" << endl;
197 
198  try {
199  a.throwit();
200  } catch (tfxx::error::Exception& e) {
201  cout << "caught exception" << endl;
202  e.report();
203  if (opt.noresume)
204  {
205  throw(e);
206  }
207  }
208 
209  cout << "survived" << endl;
210 }
#define EXCEPTIONTEST_VERSION
static void restore_report_state()
Restore previous report state.
Definition: error.cc:98
static void dont_report_on_construct()
Issue NO screen report on construction of exception.
Definition: error.cc:91
Namespace containing all components of module commandline. ,.
Definition: commandline.cc:41
Evaluates commandline by calling long_getopt. ,You may instantiate a Commandline object by passing th...
Definition: commandline.h:201
static void report_on_construct()
Issue a screen report on construction of exception.
Definition: error.cc:84
bool throwbase
struct to define options ,This struct is used to define a list of options. An example is: ...
Definition: commandline.h:136
option has no argument
Definition: commandline.h:100
bool reportonconstruct
Base class for exceptions.
Definition: error.h:78
virtual void report() const
Screen report.
Definition: error.cc:108
bool noresume
Here is the call graph for this function: