muduo exception

文章目录
  1. 1. 参考资料
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef MUDUO_BASE_EXCEPTION_H
#define MUDUO_BASE_EXCEPTION_H

#include "muduo/base/Types.h"
#include <exception>

namespace muduo
{

class Exception : public std::exception
{
public:
Exception(string what);
~Exception() noexcept override = default;

// default copy-ctor and operator= are okay.

const char* what() const noexcept override
{
return message_.c_str();
}

const char* stackTrace() const noexcept
{
return stack_.c_str();
}

private:
string message_;
string stack_;
};

} // namespace muduo

#endif // MUDUO_BASE_EXCEPTION_H
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "muduo/base/Exception.h"
#include "muduo/base/CurrentThread.h"

namespace muduo
{

Exception::Exception(string msg)
: message_(std::move(msg)),
stack_(CurrentThread::stackTrace(/*demangle=*/false))
{
}

} // namespace muduo

参考资料