9 #ifndef STK_UTIL_PARALLEL_Exception_hpp
10 #define STK_UTIL_PARALLEL_Exception_hpp
72 #include <stk_util/stk_config.h>
73 #if defined( STK_HAS_MPI )
77 #include <stk_util/environment/ReportHandler.hpp>
79 #include <stk_util/util/FeatureTest.hpp>
81 #include <stk_util/diag/StringUtil.hpp>
82 #include <stk_util/diag/Trace.hpp>
151 void throw_copy(
const std::exception &x,
const std::string &message);
216 register_exception_a(
typeid(T), x);
217 register_exception_a(
typeid(
typename T::BaseExceptionType), x);
244 ExParallel ®ister_exception_a(
const std::type_info ¶llel_exception_type,
ExParallel *exception);
252 class Registry :
public std::vector<std::pair<const std::type_info *, ExParallel *> >
280 : m_descriptionStream(),
282 m_traceback(Diag::Trace::printTraceback(Diag::Trace::Traceback::snapshot())),
299 explicit ExParallel(
const std::string & message,
int parallel = -1)
300 : m_descriptionStream(),
302 m_traceback(Diag::Trace::printTraceback(Diag::Trace::Traceback::snapshot())),
305 m_descriptionStream << message;
317 : m_descriptionStream(),
319 m_traceback(x.m_traceback),
320 m_parallel(x.m_parallel)
322 m_descriptionStream << x.m_descriptionStream.str();
339 virtual const char *
what()
const throw() {
341 m_whatBuffer = m_descriptionStream.str();
342 return m_whatBuffer.c_str();
355 m_descriptionStream.str(
"");
372 m_descriptionStream << description;
384 return m_descriptionStream.str();
395 return m_descriptionStream;
406 return m_descriptionStream;
419 m_traceback = traceback;
444 m_parallel = parallel;
468 return m_parallel != -1;
480 f(m_descriptionStream);
495 m_descriptionStream << t;
521 std::ostringstream m_descriptionStream;
522 mutable std::string m_whatBuffer;
523 std::string m_traceback;
557 explicit ExTemp(
const std::string &message)
569 T(static_cast<const T &>(x))
585 virtual const char *
what()
const throw() {
639 #ifdef SIERRA_TEMPLATE_CALL_BUG
649 class ExTemp1 :
public ExParallel,
public T
652 typedef ExTemp1<T> ParallelExceptionType;
653 typedef T BaseExceptionType;
670 explicit ExTemp1(
const std::string & message)
680 ExTemp1(
const ExTemp1 & x)
682 T(static_cast<const T &>(x))
689 virtual ~ExTemp1() throw()
698 virtual const char *what()
const throw() {
710 ExTemp1 &
operator<<(std::ostream& (*f)(std::ostream&)) {
741 ParallelExceptionType t(*
this);
756 #ifdef SIERRA_TEMPLATE_CALL_BUG
790 : std::runtime_error(message)
794 : std::runtime_error(x)
801 typedef ExTemp1<runtime_user_error> RuntimeUserError;
813 #define StackTraceMessage " exception thrown from "
814 #define ParallelStackTraceMessage " parallel exception thrown from "
815 #define ParallelStackTrace std::string(std::string(ParallelStackTraceMessage) + stk_classic::source_relative_path(STR_TRACE))
817 #endif // STK_UTIL_PARALLEL_Exception_hpp
ExTemp1< std::invalid_argument > InvalidArgument
Defined in <stdexcept>
ExParallel & clear()
Member function clear clears the contents of the exception.
void sierra_exception_throw()
Member function sierra_exception_throw is called whenever a parallel exception is constructed...
ExTemp< std::bad_alloc > BadAlloc
Defined in <new>
void parallel_throw(MPI_Comm mpi_comm)
Function parallel_throw throws a consistant exception in parallel. parallel_throw is called after the...
ExParallel & operator<<(std::ostream &(*f)(std::ostream &))
Member function operator<< passes the std manipilator functions to the ExParallel object...
void throw_copy(const std::exception &x, const std::string &append_message)
Function throw_copy throws a copy of the exception. The exception is located in the parallel exceptio...
ExParallel & registerException()
Member template function registerException registers an exception of the specified type with the para...
std::ostringstream & getDescriptionStream()
Member function getDescriptionStream returns the stream used to assemble the description.
ExParallel * findException(const std::type_info &exception_type)
Member function findException returns a pointer to the matching exception in parallel exception regis...
Template ExTemp takes a zero argument exception and makes it into a parallel throwable and put-to-abl...
ExParallel & setTraceback(const std::string &traceback)
Member function setTraceback sets the exception's traceback to the caller generating the exception...
ExParallel(const std::string &message, int parallel=-1)
bool isParallel() const
Member function isParallel returns true if the exception is being thrown in parallel.
ExTemp< std::bad_exception > BadException
Defined in
void set_exception()
Function set_exception is called on a single processor when an exception is caught. The next collective communication will propogate the exception to all processors. This flavor is called when an unknown exception (...) is caught.
ExTemp & operator<<(std::ostream &(*f)(std::ostream &))
Member function operator<< passes the std manipilator functions to the ExTemp object. This allows the manipulators to modify the description. (Currently in a limited fashion).
static ParallelThrowRegistry & instance()
Member function instance returns the singleton instance for the parallel exception registry...
Class ParallelThrowRegistry is a registry of known parallel exceptions. For the negotiation of parall...
const std::string & getTraceback() const
Member function getTraceback returns the exception's traceback string.
ExParallel & setParallel(int parallel)
Member function setParallel sets the originating processor for an exception that is being thrown in p...
virtual void throw_copy() const
Member function copy throws a copy of the original exception. It copies the original message...
ExTemp1< std::runtime_error > RuntimeError
Defined in <stdexcept>
static bool areExceptionsRegistered()
Static member function setExceptionsRegistered sets the exceptions have been registered flag...
const std::ostringstream & getDescriptionStream() const
Member function getDescriptionStream returns the stream used to assemble the description.
std::ostream & operator<<(std::ostream &s, const Bucket &k)
Print the part names for which this bucket is a subset.
ExTemp1< std::logic_error > LogicError
Defined in <stdexcept>
ExParallel(const ExParallel &x)
ExTemp< std::bad_typeid > BadTypeid
Defined in <typeinfo>
ExTemp & operator<<(const U &t)
virtual void parallel_handler()
Member function parallel_handler is called just before a parallel exception is thrown. It is guaranteed to be called in parallel on all processors, so collective communication is allowed inside Parallel_Handler. This function might be used to copy information to all processors. The default is to do nothing.
ExTemp1< std::out_of_range > OutOfRange
Defined in <stdexcept>
static void registerException()
Member function registerException registers the exception with the parallel exception registry...
void register_stl_parallel_exceptions()
Member function register_stl_parallel_exceptions registers the stl exceptions with the parallel excep...
ExTemp< T > ParallelExceptionType
Parallel exception type.
ExTemp1< std::ios_base::failure > IosBaseFailure
Defined in <ios>
ExTemp1< std::domain_error > DomainError
Defined in <stdexcept>
virtual const char * what() const
Member function what returns the exception's description.
ExParallel & operator<<(const U &t)
virtual void throw_copy() const =0
Member function throw_copy is a pure virtual function which is allows the copying and throwing of the...
ExTemp1< std::length_error > LengthError
Defined in <stdexcept>
ExTemp1< std::overflow_error > OverflowError
Defined in <stdexcept>
virtual const char * what() const
Member function what returns the exception's description.
Class ExParallel implements the features of a parallel exception. It is a std::string which stores th...
ExTemp1< std::range_error > RangeError
Defined in <stdexcept>
ExTemp< std::exception > Exception
Defined in
T BaseExceptionType
Base exception type.
ExTemp1< std::underflow_error > UnderflowError
Defined in <stdexcept>
ExTemp(const std::string &message)
ExTemp< std::bad_cast > BadCast
Defined in <typeinfo>
ExParallel & setDescription(const std::string &description)
Member function setDescription sets the value of the exception's description.
int getParallel() const
Member function getParallel returns the originating processor for a parallel exception or -1 if the e...
std::string getDescription() const
Member function getDescription returns the exception's description.
Class runtime_user_error ...