Skip to content

Commit d22f496

Browse files
authored
Merge pull request #3447 from roystgnr/disable_exceptions_fixes
Fix --disable-exceptions builds
2 parents 0d27577 + 28e8af0 commit d22f496

7 files changed

Lines changed: 23 additions & 16 deletions

File tree

examples/adjoints/adjoints_ex1/adjoints_ex1.C

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,8 @@ int main (int argc, char ** argv)
321321
// safely
322322
if (param.mesh_partitioner_type != "Default")
323323
{
324-
#ifndef LIBMESH_HAVE_RTTI
325-
libmesh_example_requires(false, "RTTI support");
324+
#if !defined(LIBMESH_HAVE_RTTI) || !defined(LIBMESH_ENABLE_EXCEPTIONS)
325+
libmesh_example_requires(false, "RTTI + exceptions support");
326326
#else
327327
// Factory failures are *verbose* in parallel; let's silence
328328
// cerr temporarily.
@@ -349,7 +349,7 @@ int main (int argc, char ** argv)
349349
libmesh_example_requires(false, param.mesh_partitioner_type + " partitioner support");
350350
}
351351
libMesh::err.rdbuf(oldbuf);
352-
#endif // LIBMESH_HAVE_RTI
352+
#endif // LIBMESH_HAVE_RTTI, LIBMESH_ENABLE_EXCEPTIONS
353353
}
354354

355355
// And an object to refine it

examples/adjoints/adjoints_ex5/adjoints_ex5.C

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,10 @@ int main (int argc, char ** argv)
462462
// In optimized mode we catch any solver errors, so that we can
463463
// write the proper footers before closing. In debug mode we just
464464
// let the exception throw so that gdb can grab it.
465-
#ifdef NDEBUG
465+
#if defined(NDEBUG) && defined(LIBMESH_ENABLE_EXCEPTIONS)
466466
try
467-
{
468467
#endif
468+
{
469469
// Now we begin the timestep loop to compute the time-accurate
470470
// solution of the equations.
471471
for (unsigned int t_step=param.initial_timestep;
@@ -777,8 +777,8 @@ int main (int argc, char ** argv)
777777
libmesh_error_msg_if(std::abs(total_sensitivity - 4.83551) >= 2.e-4,
778778
"Mismatch in sensitivity gold value!");
779779
}
780-
#ifdef NDEBUG
781780
}
781+
#if defined(NDEBUG) && defined(LIBMESH_ENABLE_EXCEPTIONS)
782782
catch (...)
783783
{
784784
libMesh::err << '[' << mesh.processor_id()

examples/adjoints/adjoints_ex7/adjoints_ex7.C

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,10 @@ int main (int argc, char ** argv)
450450
// In optimized mode we catch any solver errors, so that we can
451451
// write the proper footers before closing. In debug mode we just
452452
// let the exception throw so that gdb can grab it.
453-
#ifdef NDEBUG
453+
#if defined(NDEBUG) && defined(LIBMESH_ENABLE_EXCEPTIONS)
454454
try
455-
{
456455
#endif
456+
{
457457
// Now we begin the timestep loop to compute the time-accurate
458458
// solution of the equations.
459459
for (unsigned int t_step=param.initial_timestep;
@@ -924,8 +924,8 @@ int main (int argc, char ** argv)
924924
libmesh_error_msg_if(std::abs(accumulated_QoI_spatially_integrated_error[1] - (-0.23895256319278346)) >= 2.e-4,
925925
"Error Estimator identity not satisfied!");
926926
}
927-
#ifdef NDEBUG
928927
}
928+
#if defined(NDEBUG) && defined(LIBMESH_ENABLE_EXCEPTIONS)
929929
catch (...)
930930
{
931931
libMesh::err << '[' << mesh.processor_id()

include/base/libmesh_exceptions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@
2222

2323
#include "libmesh/libmesh_config.h"
2424

25-
#ifdef LIBMESH_ENABLE_EXCEPTIONS
2625
#include <stdexcept>
2726
#include <string>
2827
#include <sstream>
2928

30-
#define libmesh_noexcept noexcept
31-
3229
namespace libMesh {
3330

3431
/**
@@ -145,6 +142,9 @@ class SolverException: public std::exception
145142

146143
}
147144

145+
#ifdef LIBMESH_ENABLE_EXCEPTIONS
146+
#define libmesh_noexcept noexcept
147+
148148
#define LIBMESH_THROW(e) do { throw e; } while (0)
149149
#define libmesh_try try
150150
#define libmesh_catch(e) catch(e)

src/systems/equation_systems_io.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void EquationSystems::read (std::string_view name,
131131
<< "Good Luck!!\n"
132132
<< "*********************************************************************\n"
133133
<< std::endl;
134-
LIBMESH_THROW();
134+
libmesh_error();
135135
}
136136
}
137137

tests/geom/which_node_am_i_test.C

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ public:
114114
// Test the libmesh_asserts when they are enabled and exceptions
115115
// are available. If exceptions aren't available, libmesh_assert
116116
// simply aborts, so we can't unit test in that case.
117-
const Elem & prism6 = ReferenceElem::get(PRISM6);
118117
#if !defined(NDEBUG) && defined(LIBMESH_ENABLE_EXCEPTIONS)
119118
try
120119
{
120+
const Elem & prism6 = ReferenceElem::get(PRISM6);
121121
// Avoid sending confusing error messages to the console.
122122
StreamRedirector stream_redirector;
123123

@@ -136,8 +136,11 @@ public:
136136

137137
#ifdef NDEBUG
138138
// In optimized mode, we expect to get the "dummy" value 99.
139-
unsigned int n = prism6.local_side_node(0, 3);
140-
CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(99), n);
139+
{
140+
const Elem & prism6 = ReferenceElem::get(PRISM6);
141+
unsigned int n = prism6.local_side_node(0, 3);
142+
CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(99), n);
143+
}
141144
#endif
142145

143146
// Test the Prism15 midedge nodes.

tests/mesh/mesh_input.C

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,10 @@ public:
919919
// Debugging this in parallel is tricky. Let's make sure that
920920
// if we have a failure on one rank we see it on all the others
921921
// and we can go on to other tests.
922+
#ifdef LIBMESH_ENABLE_EXCEPTIONS
922923
bool threw_exception = false;
923924
try
925+
#endif // LIBMESH_ENABLE_EXCEPTIONS
924926
{
925927
for (const auto & elem : mesh.active_local_element_ptr_range())
926928
{
@@ -987,6 +989,7 @@ public:
987989
}
988990
}
989991
}
992+
#ifdef LIBMESH_ENABLE_EXCEPTIONS
990993
catch (...)
991994
{
992995
threw_exception = true;
@@ -996,6 +999,7 @@ public:
996999
if (!threw_exception)
9971000
TestCommWorld->max(threw_exception);
9981001
CPPUNIT_ASSERT(!threw_exception);
1002+
#endif // LIBMESH_ENABLE_EXCEPTIONS
9991003

10001004
TestCommWorld->sum(n_side_nodes);
10011005
CPPUNIT_ASSERT_EQUAL(n_side_nodes, n_fake_nodes);

0 commit comments

Comments
 (0)