muduo 库解析之四:Exception

源码

Exception.h

#pragmae once

#include <exception>
#include <string>

namespace muduo
{
    class Exception : public std::exception
    {
    public:
        explicit Exception(std::string msg);
        ~Exception() noexcept override = default;

        const char *what() const noexcept override //@ 重载
        {
            return msg_.c_str();
        }

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

    private:
        std::string msg_;
        std::stirng stack_;
    }
}

Exception.cc

#include "Exception.h"

#include "CurrentThread.h"

namespace muduo
{
    Exception::Exception(std::string msg) : msg_(std::move(msg)), stack_(CurrentThread::stack_trace(false))
    {
    }
}
上一篇:DRF框架(十)——drf框架里面,除了默认的增删改查,其他的一些自定义的动作,如何用代码实现


下一篇:leetcode 1105. 填充书架