/**
* Set the file name and line of where the exception appeared as
* well as the violated condition and the name of the exception as
- * a char pointer.
+ * a char pointer. This function also populates the stacktrace.
*/
void set_fields (const char *file,
const int line,
* variable. Zero if the system does not support stack traces.
*/
int n_stacktrace_frames;
+
+private:
+ /**
+ * Internal function that generates the c_string that gets printed by
+ * exception::what(). Called by the ExceptionBase constructor and
+ * set_fields.
+ */
+ void generate_message();
};
exc(""),
stacktrace (0),
n_stacktrace_frames (0)
-{}
+{
+ // Construct a minimalistic error message:
+ generate_message();
+}
cond = c;
exc = e;
- // if the system supports this, get a stacktrace how we got here
+ // If the system supports this, get a stacktrace how we got here:
+
+ if (stacktrace != 0)
+ {
+ free (stacktrace);
+ stacktrace = 0;
+ }
+
#ifdef HAVE_GLIBC_STACKTRACE
void *array[25];
n_stacktrace_frames = backtrace(array, 25);
stacktrace = backtrace_symbols(array, n_stacktrace_frames);
#endif
- // build up a string with the error message...
-
- std::ostringstream converter;
-
- converter << std::endl
- << "--------------------------------------------------------"
- << std::endl;
- // print out general data
- print_exc_data (converter);
- // print out exception specific data
- print_info (converter);
- print_stack_trace (converter);
-
- if (!deal_II_exceptions::additional_assert_output.empty())
- {
- converter << "--------------------------------------------------------"
- << std::endl
- << deal_II_exceptions::additional_assert_output
- << std::endl;
- }
-
- converter << "--------------------------------------------------------"
- << std::endl;
-
- // ... and setup the final error message with it:
- static_cast<std::runtime_error &>(*this) = std::runtime_error(converter.str());
+ // And finally populate the underlying std::runtime_error:
+ generate_message();
}
+void ExceptionBase::generate_message ()
+{
+ // build up a string with the error message...
+
+ std::ostringstream converter;
+
+ converter << std::endl
+ << "--------------------------------------------------------"
+ << std::endl;
+
+ // print out general data
+ print_exc_data (converter);
+ // print out exception specific data
+ print_info (converter);
+ print_stack_trace (converter);
+
+ if (!deal_II_exceptions::additional_assert_output.empty())
+ {
+ converter << "--------------------------------------------------------"
+ << std::endl
+ << deal_II_exceptions::additional_assert_output
+ << std::endl;
+ }
+
+ converter << "--------------------------------------------------------"
+ << std::endl;
+
+ // ... and set up std::runtime_error with it:
+ static_cast<std::runtime_error &>(*this) = std::runtime_error(converter.str());
+}
+
+
+
namespace deal_II_exceptions
{
namespace internals