Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_Exceptions.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Zoltan2: A package of combinatorial algorithms for scientific computing
4 //
5 // Copyright 2012 NTESS and the Zoltan2 contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef _ZOLTAN2_EXCEPTIONS_HPP_
11 #define _ZOLTAN2_EXCEPTIONS_HPP_
12 
17 #include <stdexcept>
18 #include <iostream>
19 #include <sstream>
20 #include <string>
21 
28 #define Z2_THROW_OUTSIDE_ERROR(env) \
29  catch (std::exception &e) { \
30  std::cerr<<(env).myRank_<<" "<<__FILE__<<","<<__LINE__<<","<<e.what()<<std::endl; \
31  throw e; \
32  }
33 
34 namespace Zoltan2 {
37 class NotImplemented : public std::exception
38 {
39 private:
40  std::string msg;
41 public:
42  NotImplemented(const char *ffile, const int lline, const char *ffunc)
43  {
44  std::ostringstream emsg;
45  emsg << ffile << ":" << lline
46  << " error: " << ffunc << " is not implemented."
47  << std::endl;
48  msg = emsg.str();
49  }
50  ~NotImplemented() throw() {}
51  const char *what() const throw() { return msg.c_str(); }
52 };
53 
54 }
55 
56 #define Z2_THROW_NOT_IMPLEMENTED \
57 { throw Zoltan2::NotImplemented(__FILE__, __LINE__, __func__zoltan2__); }
58 
59 
70 #define Z2_FORWARD_EXCEPTIONS \
71  catch (std::runtime_error &e) { throw e; } \
72  catch (std::logic_error &e) { throw e; } \
73  catch (std::bad_alloc &e) { throw e; } \
74  catch (std::exception &e) { throw e; }
75 
85 #define Z2_THROW_EXPERIMENTAL(mystr) \
86  { \
87  std::ostringstream oss; \
88  oss << (mystr) << std::endl \
89  << "To experiment with this software, configure with " \
90  << "-D Zoltan2_ENABLE_Experimental:BOOL=ON " \
91  << std::endl; \
92  throw std::runtime_error(oss.str()); \
93  }
94 
104 #define Z2_THROW_EXPERIMENTAL_WOLF(mystr) \
105  { \
106  std::ostringstream oss; \
107  oss << (mystr) << std::endl \
108  << "To experiment with this software, configure with " \
109  << "-D Zoltan2_ENABLE_Experimental_Wolf:BOOL=ON " \
110  << std::endl; \
111  throw std::runtime_error(oss.str()); \
112  }
113 
118 #define Z2_THROW_SERIAL(mystr) \
119  { \
120  std::ostringstream oss; \
121  oss << (mystr) << std::endl \
122  << "This algorithm only runs in serial (Comm_Serial or MPI_Comm with worldsize=1). " \
123  << std::endl; \
124  throw std::runtime_error(oss.str()); \
125  }
126 
127 
134 #define Z2_ASSERT_VALUE(actual, expected) \
135  { \
136  if (actual != expected) \
137  { \
138  std::ostringstream oss; \
139  oss << "Expected value " << expected << "does not match actual value"\
140  << actual << "in" << __FILE__<<", "<<__LINE__ \
141  << std::endl; \
142  throw std::runtime_error(oss.str()); \
143  }\
144  }
145 
146 #ifdef _MSC_VER
147 #if _MSC_VER >= 1300
148 #define __func__zoltan2__ __FUNCTION__
149 #else
150 #define __func__zoltan2__ "unknown zoltan2 function"
151 #endif
152 #else
153 #define __func__zoltan2__ __func__
154 #endif
155 
156 #endif
NotImplemented(const char *ffile, const int lline, const char *ffunc)
Exception thrown when a called base-class method is not implemented.
const char * what() const