MADNESS  version 0.9
worldexc.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2007,2010 Oak Ridge National Laboratory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 
31 
32  $Id$
33 */
34 
35 
36 #ifndef MADNESS_WORLD_WORLDEXC_H__INCLUDED
37 #define MADNESS_WORLD_WORLDEXC_H__INCLUDED
38 
41 
42 #include <iosfwd>
43 #include <exception>
44 #include <madness/madness_config.h>
45 
46 #ifndef MADNESS_DISPLAY_EXCEPTION_BREAK_MESSAGE
47 #define MADNESS_DISPLAY_EXCEPTION_BREAK_MESSAGE 1
48 #endif
49 
50 namespace madness {
51 
53  class MadnessException : public std::exception {
54  public:
55  const char* msg;
56  const char* assertion;
57  const int value;
58  const int line;
59  const char *function;
60  const char *filename;
61 
62  // Capturing the line/function/filename info is best done with the macros below
63  MadnessException(const char* m, const char *a, int v,
64  int l, const char *fn, const char *f)
65  : msg(m)
66  , assertion(a)
67  , value(v)
68  , line(l)
69  , function(fn)
70  , filename(f) {}
71 
72  virtual const char* what() const throw() {
73  return msg;
74  }
75 
76  };
77 
79 
81  std::ostream& operator <<(std::ostream& out, const MadnessException& e);
82 
84 
86  void exception_break(bool);
87 
88 #define MADNESS_EXCEPTION(msg,value) { \
89  madness::exception_break(MADNESS_DISPLAY_EXCEPTION_BREAK_MESSAGE); \
90  throw madness::MadnessException(msg,0,value,__LINE__,__FUNCTION__,__FILE__); \
91 }
92 
93 
94  /*
95  * Default behaviour is MADNESS_ASSERTIONS throw a MADNESS exception
96  *
97  * Configure options are MADNESS_ASSERSIONS = THROW, ASSERT, DISABLE, ABORT
98  *
99  */
100 
101 #ifdef MADNESS_ASSERTIONS_ABORT
102 # define MADNESS_ASSERT(condition) \
103  do {if (!(condition)) ((void (*)())0)();} while(0)
104 #endif
105 
106 #ifdef MADNESS_ASSERTIONS_DISABLE
107 # define MADNESS_ASSERT(condition)
108 #endif
109 
110 #ifdef MADNESS_ASSERTIONS_ASSERT
111 # include <cassert>
112 # define MADNESS_ASSERT(condition) assert(condition)
113 #endif
114 
115 #ifdef MADNESS_ASSERTIONS_THROW
116 # define MADNESS_STRINGIZE(X) #X
117 # define MADNESS_EXCEPTION_AT(F, L) MADNESS_STRINGIZE(F) "(" MADNESS_STRINGIZE(L) ")"
118 # define MADNESS_ASSERT(condition) \
119  do { \
120  if (!(condition)) { \
121  madness::exception_break(MADNESS_DISPLAY_EXCEPTION_BREAK_MESSAGE); \
122  throw madness::MadnessException("MADNESS ASSERTION FAILED: " MADNESS_EXCEPTION_AT( __FILE__, __LINE__ ), \
123  #condition,0,__LINE__,__FUNCTION__,__FILE__); \
124  } \
125  } while (0)
126 #endif
127 
128 }
129 
130 #endif // MADNESS_WORLD_WORLDEXC_H__INCLUDED
const char * assertion
Definition: worldexc.h:56
void exception_break(bool message)
This function is executed just before a madness exception is thrown.
Definition: world.cc:243
const int value
Definition: worldexc.h:57
MadnessException(const char *m, const char *a, int v, int l, const char *fn, const char *f)
Definition: worldexc.h:63
NDIM & f
Definition: mra.h:2179
const char * filename
Definition: worldexc.h:60
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
const double m
Definition: gfit.cc:199
std::ostream & operator<<(std::ostream &s, const ContractedGaussianShell &c)
Definition: chem/molecularbasis.cc:38
virtual const char * what() const
Definition: worldexc.h:72
const char * msg
Definition: worldexc.h:55
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
const int line
Definition: worldexc.h:58
Most exceptions thrown in MADNESS should be derived from these.
Definition: worldexc.h:53
Function< complexd, 3 > function
Definition: envelopedpulse.h:45