3 ms·
There are functions that can capture or print stack traces, such as the backtrace() family on OS X (which has a "man" page) or just the "pstack" command on Linu
by makecheck 11y ago
There are functions that can capture or print stack traces, such as the backtrace() family on OS X (which has a "man" page) or just the "pstack" command on Linux. It is very useful to have a function in your code base that invokes one of these on demand.
Then you can do interesting things like print a stack trace at a "throw" point if you suspect a problem, or capture a trace into an exception base class in debug modes for printing at catch points, or even as a form of non-crashing assertion to log traces whenever unexpected conditions arise.