From: Benjamin Kosnik terminate
@@ -216,10 +217,78 @@
There are six flavors each of new and delete, so
- make certain that you're using the right ones! Here are quickie
- descriptions of new:
+
terminateIf you are having difficulty with uncaught exceptions and want a + little bit of help debugging the causes of the core dumps, you can + make use of a GNU extension in GCC 3.1 and later: +
+
+ #include <exception>
+
+ int main()
+ {
+ std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
+ ...
+ throw anything;
+ }
+ The __verbose_terminate_handler function obtains the name
+ of the current exception, attempts to demangle it, and prints it to
+ stderr. If the exception is derived from std::exception
+ then the output from what() will be included.
+
Any replacement termination function is required to kill the program + without returning; this one calls abort. +
+For example: +
+
+ #include <exception>
+ #include <stdexcept>
+
+ struct argument_error : public std::runtime_error
+ {
+ argument_error(const std::string& s): std::runtime_error(s) { }
+ };
+
+ int main(int argc)
+ {
+ std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
+ if (argc > 5)
+ throw argument_error("argc is greater than 5!");
+ else
+ throw argc;
+ }
+
+ In GCC 3.1 and later, this gives +
++ % ./a.out + terminate called after throwing a `int' + Aborted + % ./a.out f f f f f f f f f f f + terminate called after throwing an instance of `argument_error' + what(): argc is greater than 5! + Aborted + %+
The 'Aborted' line comes from the call to abort(), of course. +
+UPDATE: Starting with GCC 3.4, this is the default
+ termination handler; nothing need be done to use it. To go back to
+ the previous "silent death" method, simply include
+ <exception> and <cstdlib>,
+ and call
+
+ std::set_terminate(std::abort);+
Return to top of page or + to the FAQ. +
+ +There are six flavors each of new and
+ delete, so make certain that you're using the right
+ ones! Here are quickie descriptions of new:
bad_alloc on errors;
@@ -277,7 +346,7 @@
If you have read the source
documentation for namespace abi then you are aware
of the cross-vendor C++ ABI which we use. One of the exposed
diff --git a/libstdc++-v3/docs/html/19_diagnostics/howto.html b/libstdc++-v3/docs/html/19_diagnostics/howto.html
index 2b5cd22850a..4cd2dc78371 100644
--- a/libstdc++-v3/docs/html/19_diagnostics/howto.html
+++ b/libstdc++-v3/docs/html/19_diagnostics/howto.html
@@ -38,7 +38,6 @@
terminateterminateIf you are having difficulty with uncaught exceptions and want a - little bit of help debugging the causes of the core dumps, you can - make use of a GNU extension in GCC 3.1 and later: -
-
- #include <exception>
-
- int main()
- {
- std::set_terminate (__gnu_cxx::__verbose_terminate_handler);
- ...
- throw anything;
- }
- The __verbose_terminate_handler function obtains the name
- of the current exception, attempts to demangle it, and prints it to
- stderr. If the exception is derived from std::exception
- then the output from what() will be included.
-
Any replacement termination function is required to kill the program - without returning; this one calls abort. -
-For example: -
-
- #include <exception>
- #include <stdexcept>
-
- struct BLARGH : std::runtime_error
- {
- BLARGH (const string& whatarg)
- : std::runtime_error(whatarg) { }
- };
-
- int main (int argc)
- {
- std::set_terminate (__gnu_cxx::__verbose_terminate_handler);
- if (argc > 5)
- throw BLARGH("argc is greater than 5!");
- else
- throw argc;
- }
- In GCC 3.1 and later, this gives -
-- % ./a.out - terminate called after throwing a `int' - Aborted - % ./a.out f f f f f f f f f f f - terminate called after throwing a `BLARGH' - what(): argc is greater than 5! - Aborted - %-
The 'Aborted' line comes from the call to abort(), of course. -
-UPDATE: Starting with GCC 3.4, this is the default
- termination handler; nothing need be done to use it. To go back to
- the previous "silent death" method, simply include
- <exception> and <cstdlib>,
- and call
-
- std::set_terminate (std::abort);-
Return to top of page or - to the FAQ. -
- -terminateterminate