Skip to content

Commit 2ad0a66

Browse files
committed
Fix the PCMSOLVER_ERROR macro. It now prints out a more informative error message.
1 parent 28f567f commit 2ad0a66

17 files changed

+41
-72
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
for a more detailed explanation.
3636
- **BREAKING CHANGE** The minimum required version of Eigen is now 3.3.0
3737
The version bundled with the code has been accordingly updated.
38+
- The `PCMSOLVER_ERROR` macro now takes only one argument and prints out a more
39+
informative error message.
3840

3941
### Deprecated
4042

include/Config.hpp.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@
5151
# define UNUSED_FUNCTION(x) UNUSED_ ## x
5252
#endif
5353

54-
55-
#include <boost/current_function.hpp>
56-
5754
// Inspired from Eigen EIGEN_DEFAULT_DENSE_INDEX_TYPE
5855
#ifndef PCMSOLVER_DEFAULT_INDEX_TYPE
5956
#define PCMSOLVER_DEFAULT_INDEX_TYPE int

include/ErrorHandling.hpp

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include <cassert>
2828
#include <cstdio>
2929
#include <cstdlib>
30+
#include <iostream>
31+
#include <sstream>
32+
#include <string>
3033

3134
/*! \file ErrorHandling.hpp
3235
* \brief Provide macros for error handling
@@ -67,30 +70,16 @@
6770
*http://www.boost.org/doc/libs/1_59_0/doc/html/boost_staticassert.html
6871
*/
6972

70-
/*! \brief Kills execution and prints out error message to stderr
71-
* \param message Error message
72-
* \param function Name of the function killing execution
73-
* \param code Error code. Defaults to EXIT_FAILURE
74-
*/
75-
inline void pcmsolver_die(const std::string & message, const std::string & function,
76-
int code = EXIT_FAILURE) {
77-
pcmsolver_die(message.c_str(), function.c_str(), code);
78-
}
79-
80-
/*! \brief Kills execution and prints out error message to stderr
81-
* \param message Error message
82-
* \param function Name of the function killing execution
83-
* \param code Error code. Defaults to EXIT_FAILURE
84-
*/
85-
inline void pcmsolver_die(const char * message, const char * function,
86-
int code = EXIT_FAILURE) {
87-
std::fprintf(stderr, "In function: %s\n", function);
88-
std::fprintf(stderr, "PCMSolver fatal error %i: %s\n", code, message);
89-
std::exit(EXIT_FAILURE);
90-
}
91-
9273
/// Macro to be used to signal error conditions
93-
#define PCMSOLVER_ERROR(arg, func) pcmsolver_die(arg, func)
74+
#define PCMSOLVER_ERROR(message) \
75+
{ \
76+
std::ostringstream _err; \
77+
_err << "PCMSolver fatal error.\n" \
78+
<< " In function " << __func__ << " at line " << __LINE__ << " of file " \
79+
<< __FILE__ << "\n" << message << std::endl; \
80+
std::fprintf(stderr, "%s\n", _err.str().c_str()); \
81+
std::exit(EXIT_FAILURE); \
82+
}
9483

9584
/// Macro to be used for assertions
9685
#define PCMSOLVER_ASSERT(arg) assert(arg)

src/bin/run_pcm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int main(int argc, char * argv[]) {
6161
out_stream.open("pcmsolver.out");
6262

6363
if (argc > 2)
64-
PCMSOLVER_ERROR("Too many arguments supplied", "run_pcm");
64+
PCMSOLVER_ERROR("Too many arguments supplied");
6565
TIMER_ON("Input parsing");
6666
Input parsed(argv[1]);
6767
TIMER_OFF("Input parsing");

src/cavity/Cavity.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,32 +95,27 @@ void Cavity::loadCavity(const std::string & fname) {
9595
// 1. Get the weights
9696
cnpy::NpyArray raw_weights = loaded_cavity["weights"];
9797
if (raw_weights.shape[0] != nElements_)
98-
PCMSOLVER_ERROR("elementArea_: incoherent dimensions read in",
99-
BOOST_CURRENT_FUNCTION);
98+
PCMSOLVER_ERROR("elementArea_: incoherent dimensions read in");
10099
elementArea_ = cnpy::custom::npy_to_eigen<double>(raw_weights);
101100
// 2. Get the element sphere center
102101
cnpy::NpyArray raw_elSphCenter = loaded_cavity["elSphCenter"];
103102
if (raw_elSphCenter.shape[1] != nElements_)
104-
PCMSOLVER_ERROR("elementSphereCenter_: incoherent dimensions read in",
105-
BOOST_CURRENT_FUNCTION);
103+
PCMSOLVER_ERROR("elementSphereCenter_: incoherent dimensions read in");
106104
elementSphereCenter_ = cnpy::custom::npy_to_eigen<double>(raw_elSphCenter);
107105
// 3. Get the element radius
108106
cnpy::NpyArray raw_elRadius = loaded_cavity["elRadius"];
109107
if (raw_elRadius.shape[0] != nElements_)
110-
PCMSOLVER_ERROR("elementRadius_: incoherent dimensions read in",
111-
BOOST_CURRENT_FUNCTION);
108+
PCMSOLVER_ERROR("elementRadius_: incoherent dimensions read in");
112109
elementRadius_ = cnpy::custom::npy_to_eigen<double>(raw_elRadius);
113110
// 4. Get the centers
114111
cnpy::NpyArray raw_centers = loaded_cavity["centers"];
115112
if (raw_centers.shape[1] != nElements_)
116-
PCMSOLVER_ERROR("elementCenter_: incoherent dimensions read in",
117-
BOOST_CURRENT_FUNCTION);
113+
PCMSOLVER_ERROR("elementCenter_: incoherent dimensions read in");
118114
elementCenter_ = cnpy::custom::npy_to_eigen<double>(raw_centers);
119115
// 5. Get the normal vectors
120116
cnpy::NpyArray raw_normals = loaded_cavity["normals"];
121117
if (raw_normals.shape[1] != nElements_)
122-
PCMSOLVER_ERROR("elementNormal_: incoherent dimensions read in",
123-
BOOST_CURRENT_FUNCTION);
118+
PCMSOLVER_ERROR("elementNormal_: incoherent dimensions read in");
124119
elementNormal_ = cnpy::custom::npy_to_eigen<double>(raw_normals);
125120

126121
// Reconstruct the elements_ vector

src/cavity/Element.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ void tangent_and_bitangent(const Eigen::Vector3d & n_, Eigen::Vector3d & t_,
141141
M.col(1) = t_;
142142
M.col(2) = b_;
143143
if (boost::math::sign(M.determinant()) != 1) {
144-
PCMSOLVER_ERROR("Frenet-Serret local frame is not left-handed!",
145-
BOOST_CURRENT_FUNCTION);
144+
PCMSOLVER_ERROR("Frenet-Serret local frame is not left-handed!");
146145
}
147146
}

src/cavity/GePolCavity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ void GePolCavity::build(const std::string & suffix, int maxts, int maxsph,
238238
std::string message = pcm::to_string(equal_elements.size()) +
239239
" cavity finite element centers overlap exactly!\n" +
240240
list_of_pairs;
241-
PCMSOLVER_ERROR(message, BOOST_CURRENT_FUNCTION);
241+
PCMSOLVER_ERROR(message);
242242
}
243243
// Calculate normal vectors
244244
elementNormal_ = elementCenter_ - elementSphereCenter_;

src/green/AnisotropicLiquid.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,14 @@ KernelD AnisotropicLiquid<DerivativeTraits>::exportKernelD_impl() const {
8888
template <typename DerivativeTraits>
8989
double AnisotropicLiquid<DerivativeTraits>::singleLayer_impl(
9090
const Element & /* e */, double /* factor */) const {
91-
PCMSOLVER_ERROR("Not implemented yet for AnisotropicLiquid",
92-
BOOST_CURRENT_FUNCTION);
91+
PCMSOLVER_ERROR("Not implemented yet for AnisotropicLiquid");
9392
return 0.0;
9493
}
9594

9695
template <typename DerivativeTraits>
9796
double AnisotropicLiquid<DerivativeTraits>::doubleLayer_impl(
9897
const Element & /* e */, double /* factor */) const {
99-
PCMSOLVER_ERROR("Not implemented yet for AnisotropicLiquid",
100-
BOOST_CURRENT_FUNCTION);
98+
PCMSOLVER_ERROR("Not implemented yet for AnisotropicLiquid");
10199
return 0.0;
102100
}
103101

src/green/IonicLiquid.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ KernelD IonicLiquid<DerivativeTraits>::exportKernelD_impl() const {
7474
template <typename DerivativeTraits>
7575
double IonicLiquid<DerivativeTraits>::singleLayer_impl(const Element & /* e */,
7676
double /* factor */) const {
77-
PCMSOLVER_ERROR("Not implemented yet for IonicLiquid", BOOST_CURRENT_FUNCTION);
77+
PCMSOLVER_ERROR("Not implemented yet for IonicLiquid");
7878
return 0.0;
7979
}
8080

8181
template <typename DerivativeTraits>
8282
double IonicLiquid<DerivativeTraits>::doubleLayer_impl(const Element & /* e */,
8383
double /* factor */) const {
84-
PCMSOLVER_ERROR("Not implemented yet for IonicLiquid", BOOST_CURRENT_FUNCTION);
84+
PCMSOLVER_ERROR("Not implemented yet for IonicLiquid");
8585
return 0.0;
8686
}
8787

src/interface/Input.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void Input::reader(const std::string & filename) {
139139
// Just initialize the solvent object in this class
140140
hasSolvent_ = true;
141141
if (solvents().find(name) == solvents().end()) {
142-
PCMSOLVER_ERROR("Solvent " + name + " NOT found!", BOOST_CURRENT_FUNCTION);
142+
PCMSOLVER_ERROR("Solvent " + name + " NOT found!");
143143
} else {
144144
solvent_ = solvents()[name];
145145
}
@@ -332,8 +332,7 @@ void Input::initMolecule() {
332332
std::cout << molecule_ << std::endl;
333333
PCMSOLVER_ERROR("Some atoms do not have a radius attached. Please specify a "
334334
"radius for all atoms (see "
335-
"http://pcmsolver.readthedocs.org/en/latest/users/input.html)!",
336-
BOOST_CURRENT_FUNCTION);
335+
"http://pcmsolver.readthedocs.org/en/latest/users/input.html)!");
337336
}
338337
}
339338

0 commit comments

Comments
 (0)