https://github.com/leozhang1/QtInterpreter这个链接 Exception.h代码 展示
时间: 2023-09-27 20:11:39 浏览: 42
以下是Exception.h的代码:
```cpp
#ifndef EXCEPTION_H
#define EXCEPTION_H
#include <string>
#include <exception>
class Exception : public std::exception
{
public:
Exception(const std::string& msg) : m_msg(msg) {}
~Exception() throw() {}
const char* what() const throw() { return m_msg.c_str(); }
private:
std::string m_msg;
};
#endif // EXCEPTION_H
```
这是一个自定义的异常类,继承了`std::exception`。在构造函数中传入一个字符串`msg`,即异常信息,在`what()`函数中返回这个异常信息。
相关问题
https://github.com/leozhang1/QtInterpreter这个链接的代码 展示
这个链接是一个基于Qt框架的解释器,可以解释执行简单的脚本语言。
如果你想要查看代码,可以按照以下步骤进行:
1. 首先,你需要在本地安装Git和Qt Creator。
2. 打开Qt Creator,选择“文件”->“新建文件或项目”。
3. 在弹出的对话框中,选择“从版本控制”->“Git”。
4. 在“存储库位置”中输入 https://github.com/leozhang1/QtInterpreter.git,并选择本地存储位置,然后点击“克隆”。
5. 克隆完成后,在Qt Creator中打开该项目并编译运行即可查看代码。
如果你只是想在线查看代码,可以直接在GitHub上浏览该项目的源代码。
https://github.com/leozhang1/QtInterpreter这个链接 Exception.cpp代码 展示
下面是QtInterpreter项目中Exception.cpp的代码:
```
#include "Exception.h"
Exception::Exception(const std::string& error) : error(error) {}
Exception::Exception(const char* error) : error(error) {}
const char* Exception::what() const noexcept {
return error.c_str();
}
```
该文件定义了一个名为Exception的类,它继承自std::exception类。Exception类有两个构造函数:一个接受一个std::string类型的错误信息,另一个接受一个char*类型的错误信息。类还有一个what()函数,用于返回错误信息。