glucat  0.8.4
try_catch.h
Go to the documentation of this file.
1 #ifndef _GLUCAT_TRY_CATCH_H
2 #define _GLUCAT_TRY_CATCH_H
3 /***************************************************************************
4  GluCat : Generic library of universal Clifford algebra templates
5  try_catch.h : Catch exceptions
6  -------------------
7  begin : Sun 2001-12-20
8  copyright : (C) 2001-2010 by Paul C. Leopardi
9  ***************************************************************************
10 
11  This library is free software: you can redistribute it and/or modify
12  it under the terms of the GNU Lesser General Public License as published
13  by the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public License
22  along with this library. If not, see <http://www.gnu.org/licenses/>.
23 
24  ***************************************************************************
25  This library is based on a prototype written by Arvind Raja and was
26  licensed under the LGPL with permission of the author. See Arvind Raja,
27  "Object-oriented implementations of Clifford algebras in C++: a prototype",
28  in Ablamowicz, Lounesto and Parra (eds.)
29  "Clifford algebras with numeric and symbolic computations", Birkhauser, 1996.
30  ***************************************************************************
31  See also Arvind Raja's original header comments in glucat.h
32  ***************************************************************************/
33 
34 namespace glucat
35 {
37  typedef int (*intfn)();
38 
40  typedef int (*intintfn)(int);
41 
43  int try_catch(intfn f);
44 
46  int try_catch(intintfn f, int arg);
47 
49  int try_catch(intfn f)
50  {
51  int result = 0;
52  try
53  { result = (*f)(); }
54  catch (const glucat_error& e)
55  { e.print_error_msg(); }
56  catch (const std::bad_alloc& e)
57  { std::cerr << "bad_alloc" << std::endl; }
58  catch (...)
59  { std::cerr << "unexpected exception" << std::endl; }
60  return result;
61  }
62 
64  int try_catch(intintfn f, int arg)
65  {
66  int result = 0;
67  try
68  { result = (*f)(arg); }
69  catch (const glucat_error& e)
70  { e.print_error_msg(); }
71  catch (const std::bad_alloc& e)
72  { std::cerr << "bad_alloc" << std::endl; }
73  catch (...)
74  { std::cerr << "unexpected exception" << std::endl; }
75  return result;
76  }
77 }
78 #endif // _GLUCAT_TRY_CATCH_H
PyClical.e
def e(obj)
Definition: PyClical.pyx:1886
glucat::try_catch
int try_catch(intfn f)
Exception catching for functions returning int.
Definition: try_catch.h:78
glucat::glucat_error
Abstract exception class.
Definition: errors.h:71
glucat::intintfn
int(* intintfn)(int)
For exception catching: pointer to function of int returning int.
Definition: try_catch.h:69
glucat
Definition: clifford_algebra.h:39
glucat::intfn
int(* intfn)()
For exception catching: pointer to function returning int.
Definition: try_catch.h:66