1// excerpts from http://code.google.com/p/muduo/
2//
3// Use of this source code is governed by a BSD-style license
4// that can be found in the License file.
5//
6// Author: Shuo Chen (giantchen at gmail dot com)
7
8#include "Exception.h"
9
10#include <cxxabi.h>
11#include <execinfo.h>
12#include <stdlib.h>
13
14using namespace muduo;
15
16Exception::Exception(const char* what)
17  : message_(what)
18{
19  const int len = 200;
20  void* buffer[len];
21  int nptrs = ::backtrace(buffer, len);
22  char** strings = ::backtrace_symbols(buffer, nptrs);
23  if (strings)
24  {
25    for (int i = 0; i < nptrs; ++i)
26    {
27      // TODO demangle funcion name with abi::__cxa_demangle
28      stack_.append(strings[i]);
29      stack_.push_back('\n');
30    }
31    free(strings);
32  }
33}
34
35Exception::~Exception() throw ()
36{
37}
38
39const char* Exception::what() const throw()
40{
41  return message_.c_str();
42}
43
44const char* Exception::stackTrace() const throw()
45{
46  return stack_.c_str();
47}
48
49