<li><a href="#1">Types</a></li>
<li><a href="#2">Implementation properties</a></li>
<li><a href="#3">Start and Termination</a></li>
- <li><a href="#4">Dynamic memory management</a></li>
- <li><a href="#5">RTTI, the ABI, and demangling</a></li>
+ <li><a href="#4">Verbose <code>terminate</code></a></li>
+ <li><a href="#5">Dynamic memory management</a></li>
+ <li><a href="#6">RTTI, the ABI, and demangling</a></li>
</ul>
<hr />
</p>
<hr />
-<h2><a name="4">Dynamic memory management</a></h2>
- <p>There are six flavors each of <code>new</code> and <code>delete</code>, so
- make certain that you're using the right ones! Here are quickie
- descriptions of <code>new</code>:
+<h2><a name="4">Verbose <code>terminate</code></a></h2>
+ <p>If 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:
+ </p>
+ <pre>
+ #include <exception>
+
+ int main()
+ {
+ std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
+ ...
+ throw <em>anything</em>;
+ }</pre>
+ <p>The <code> __verbose_terminate_handler </code> function obtains the name
+ of the current exception, attempts to demangle it, and prints it to
+ stderr. If the exception is derived from <code> std::exception </code>
+ then the output from <code>what()</code> will be included.
+ </p>
+ <p>Any replacement termination function is required to kill the program
+ without returning; this one calls abort.
+ </p>
+ <p>For example:
+ </p>
+ <pre>
+ #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;
+ }
+ </pre>
+ <p>In GCC 3.1 and later, this gives
+ </p>
+ <pre>
+ % ./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
+ %</pre>
+ <p>The 'Aborted' line comes from the call to abort(), of course.
+ </p>
+ <p><strong>UPDATE:</strong> 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
+ <code><exception></code> and <code><cstdlib></code>,
+ and call
+ </p>
+ <pre>
+ std::set_terminate(std::abort);</pre>
+ <p>Return <a href="#top">to top of page</a> or
+ <a href="../faq/index.html">to the FAQ</a>.
+ </p>
+
+<hr />
+<h2><a name="5">Dynamic memory management</a></h2>
+ <p>There are six flavors each of <code>new</code> and
+ <code>delete</code>, so make certain that you're using the right
+ ones! Here are quickie descriptions of <code>new</code>:
</p>
<ul>
<li>single object form, throwing a <code>bad_alloc</code> on errors;
</p>
<hr />
-<h2><a name="5">RTTI, the ABI, and demangling</a></h2>
+<h2><a name="6">RTTI, the ABI, and demangling</a></h2>
<p>If you have read the <a href="../documentation.html#4">source
documentation</a> for <code> namespace abi </code> then you are aware
of the cross-vendor C++ ABI which we use. One of the exposed
<li><a href="#1">Adding data to exceptions</a></li>
<li><a href="#2">Exception class hierarchy diagram</a></li>
<li><a href="#3">Concept checkers -- <strong>new and improved!</strong></a></li>
- <li><a href="#4">Verbose <code>terminate</code></a></li>
</ul>
<hr />
<a href="../faq/index.html">to the FAQ</a>.
</p>
-<hr />
-<h2><a name="4">Verbose <code>terminate</code></a></h2>
- <p>If 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:
- </p>
- <pre>
- #include <exception>
-
- int main()
- {
- std::set_terminate (__gnu_cxx::__verbose_terminate_handler);
- ...
- throw <em>anything</em>;
- }</pre>
- <p>The <code> __verbose_terminate_handler </code> function obtains the name
- of the current exception, attempts to demangle it, and prints it to
- stderr. If the exception is derived from <code> std::exception </code>
- then the output from <code>what()</code> will be included.
- </p>
- <p>Any replacement termination function is required to kill the program
- without returning; this one calls abort.
- </p>
- <p>For example:
- </p>
- <pre>
- #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;
- }</pre>
- <p>In GCC 3.1 and later, this gives
- </p>
- <pre>
- % ./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
- %</pre>
- <p>The 'Aborted' line comes from the call to abort(), of course.
- </p>
- <p><strong>UPDATE:</strong> 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
- <code><exception></code> and <code><cstdlib></code>,
- and call
- </p>
- <pre>
- std::set_terminate (std::abort);</pre>
- <p>Return <a href="#top">to top of page</a> or
- <a href="../faq/index.html">to the FAQ</a>.
- </p>
-
-
<!-- ####################################################### -->
<hr />
<li><a href="18_support/howto.html#1">Types</a></li>
<li><a href="18_support/howto.html#2">Implementation properties</a></li>
<li><a href="18_support/howto.html#3">Start and Termination</a></li>
- <li><a href="18_support/howto.html#4">Dynamic memory management</a></li>
- <li><a href="18_support/howto.html#5">RTTI, the ABI, and demangling</a></li>
+ <li><a href="18_support/howto.html#4">Verbose <code>terminate</code></a></li>
+ <li><a href="18_support/howto.html#6">Dynamic memory management</a></li>
+ <li><a href="18_support/howto.html#7">RTTI, the ABI, and demangling</a></li>
</ul>
</li>
<li><a href="19_diagnostics/howto.html#1">Adding data to exceptions</a></li>
<li><a href="19_diagnostics/howto.html#2">Exception class hierarchy diagram</a></li>
<li><a href="19_diagnostics/howto.html#3">Concept checkers -- <strong>new and improved!</strong></a></li>
- <li><a href="19_diagnostics/howto.html#4">Verbose <code>terminate</code></a></li>
</ul>
</li>