Skip to content
Merged
111 changes: 91 additions & 20 deletions Makefile.in

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions include/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ include_HEADERS = \
base/getpot.h \
base/id_types.h \
base/libmesh.h \
base/libmesh_abort.h \
base/libmesh_base.h \
base/libmesh_common.h \
base/libmesh_documentation.h \
Expand Down
27 changes: 10 additions & 17 deletions include/base/libmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace Parallel {
class Communicator;
}

class PerfLog;
enum SolverPackage : int;

/**
Expand Down Expand Up @@ -147,6 +148,15 @@ class LibMeshInit
// protected and forces us to use a named destructor manually
vtkMPIController * _vtk_mpi_controller;
#endif

#ifdef LIBMESH_ENABLE_EXCEPTIONS
static std::terminate_handler _old_terminate_handler;
#endif

static PerfLog & perf_log();

friend void libmesh_abort();
friend void libmesh_terminate_handler();
};

/**
Expand All @@ -165,23 +175,6 @@ bool initialized ();
*/
bool closed ();

/**
* A terminate handler. libMesh sets this to handle uncaught
* exceptions; it can also be called manually to print stack traces
* and perf logs and call MPI
*/
void libmesh_terminate_handler();

/**
* Toggle hardware trap floating point exceptions
*/
void enableFPE(bool on);

/**
* Toggle libMesh reporting of segmentation faults
*/
void enableSEGV(bool on);

/**
* \returns \p true if the argument \p arg was specified on the command line,
* \p false otherwise.
Expand Down
37 changes: 37 additions & 0 deletions include/base/libmesh_abort.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// The libMesh Finite Element Library.
// Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner

// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.

// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA



#ifndef LIBMESH_LIBMESH_ABORT_H
#define LIBMESH_LIBMESH_ABORT_H

#include "libmesh/libmesh_config.h"

namespace libMesh {

/**
* Abort as soon as possible.
*
* This cleans up stream buffers, aborts with MPI_Abort (if MPI
* is initialized), and falls back on std::abort afterward.
*/
[[noreturn]] void libmesh_abort();

}

#endif // LIBMESH_LIBMESH_ABORT_H
27 changes: 26 additions & 1 deletion include/base/libmesh_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,37 @@

#include "libmesh/libmesh_config.h"

#include "libmesh/libmesh_abort.h"

#include <stdexcept>
#include <string>
#include <sstream>

namespace libMesh {

/**
* A terminate handler. libMesh sets this to handle uncaught
* exceptions; it can also be called manually to cleanup, print
* any diagnostics, do cleanup, and abort.
*
* If an uncaught exception is a TerminationException, as thrown by
* libmesh_terminate(), the handler avoids any diagnostic output.
*
* If an uncaught exception is a std::exception, its message is
* printed, followed by stack trace and performance log output.
*/
void libmesh_terminate_handler();

/**
* Toggle hardware trap floating point exceptions
*/
void enableFPE(bool on);

/**
* Toggle libMesh reporting of segmentation faults
*/
void enableSEGV(bool on);

/**
* A class to represent the internal "this should never happen"
* errors, to be thrown by "libmesh_error();"
Expand Down Expand Up @@ -192,7 +217,7 @@ class TerminationException

#else

#define LIBMESH_THROW(e) do { libMesh::err << e.what(); std::abort(); } while (0)
#define LIBMESH_THROW(e) do { libMesh::err << e.what(); libmesh_abort(); } while (0)
#define libmesh_rethrow
#define libmesh_try
#define libmesh_catch(e) if (0)
Expand Down
1 change: 1 addition & 0 deletions include/include_HEADERS
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ include_HEADERS = \
base/getpot.h \
base/id_types.h \
base/libmesh.h \
base/libmesh_abort.h \
base/libmesh_base.h \
base/libmesh_common.h \
base/libmesh_documentation.h \
Expand Down
4 changes: 4 additions & 0 deletions include/libmesh/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ BUILT_SOURCES = \
getpot.h \
id_types.h \
libmesh.h \
libmesh_abort.h \
libmesh_augment_std_namespace.h \
libmesh_base.h \
libmesh_common.h \
Expand Down Expand Up @@ -643,6 +644,9 @@ id_types.h: $(top_srcdir)/include/base/id_types.h
libmesh.h: $(top_srcdir)/include/base/libmesh.h
$(AM_V_GEN)rm -f $@ && $(LN_S) -f $< $@

libmesh_abort.h: $(top_srcdir)/include/base/libmesh_abort.h
$(AM_V_GEN)rm -f $@ && $(LN_S) -f $< $@

libmesh_augment_std_namespace.h: $(top_srcdir)/include/base/libmesh_augment_std_namespace.h
$(AM_V_GEN)rm -f $@ && $(LN_S) -f $< $@

Expand Down
13 changes: 8 additions & 5 deletions include/libmesh/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,11 @@ vtkversion = @vtkversion@
EXTRA_DIST = rebuild_makefile.sh
BUILT_SOURCES = dirichlet_boundaries.h dof_map.h dof_map_base.h \
dof_object.h factory.h float128_shims.h getpot.h id_types.h \
libmesh.h libmesh_augment_std_namespace.h libmesh_base.h \
libmesh_common.h libmesh_documentation.h libmesh_exceptions.h \
libmesh_logging.h libmesh_singleton.h libmesh_version.h \
multi_predicates.h periodic_boundaries.h periodic_boundary.h \
periodic_boundary_base.h print_trace.h \
libmesh.h libmesh_abort.h libmesh_augment_std_namespace.h \
libmesh_base.h libmesh_common.h libmesh_documentation.h \
libmesh_exceptions.h libmesh_logging.h libmesh_singleton.h \
libmesh_version.h multi_predicates.h periodic_boundaries.h \
periodic_boundary.h periodic_boundary_base.h print_trace.h \
reference_counted_object.h reference_counter.h \
single_predicates.h sparsity_pattern.h variable.h \
variant_filter_iterator.h enum_convergence_flags.h \
Expand Down Expand Up @@ -979,6 +979,9 @@ id_types.h: $(top_srcdir)/include/base/id_types.h
libmesh.h: $(top_srcdir)/include/base/libmesh.h
$(AM_V_GEN)rm -f $@ && $(LN_S) -f $< $@

libmesh_abort.h: $(top_srcdir)/include/base/libmesh_abort.h
$(AM_V_GEN)rm -f $@ && $(LN_S) -f $< $@

libmesh_augment_std_namespace.h: $(top_srcdir)/include/base/libmesh_augment_std_namespace.h
$(AM_V_GEN)rm -f $@ && $(LN_S) -f $< $@

Expand Down
Loading