Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit 81f059a

Browse files
authored
Merge pull request #97 from cyanray/dev/cyanray
加入常用异常(网络异常和MAH异常)
2 parents 6566209 + 3979369 commit 81f059a

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
#ifndef mirai_cpp_exceptions_exceptions_hpp_H_
3+
#define mirai_cpp_exceptions_exceptions_hpp_H_
4+
5+
#include "mirai_api_http_exception.hpp"
6+
#include "network_exception.hpp"
7+
8+
#endif // !mirai_cpp_exceptions_exceptions_hpp_H_
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
#ifndef mirai_cpp_exceptions_mirai_api_http_exception_hpp_H_
3+
#define mirai_cpp_exceptions_mirai_api_http_exception_hpp_H_
4+
5+
#include <exception>
6+
#include <string>
7+
8+
namespace Cyan
9+
{
10+
/**
11+
* @brief mirai-api-http 异常
12+
*/
13+
class MiraiApiHttpException : public std::runtime_error
14+
{
15+
public:
16+
const int Code;
17+
const string Message;
18+
MiraiApiHttpException(int code, const std::string& error_msg) :
19+
Code(code),
20+
Message(error_msg),
21+
std::runtime_error("mirai-api-http 错误: " + error_msg) {}
22+
virtual ~MiraiApiHttpException() = default;
23+
};
24+
25+
}
26+
27+
#endif // !mirai_cpp_exceptions_mirai_api_http_exception_hpp_H_
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
#ifndef mirai_cpp_exceptions_network_exception_hpp_H_
3+
#define mirai_cpp_exceptions_network_exception_hpp_H_
4+
5+
#include <exception>
6+
7+
namespace Cyan
8+
{
9+
/**
10+
* @brief 网络错误异常
11+
*/
12+
class NetworkException : public std::runtime_error
13+
{
14+
public:
15+
NetworkException(): std::runtime_error("网络错误.") {}
16+
virtual ~NetworkException() = default;
17+
};
18+
19+
}
20+
21+
#endif // !mirai_cpp_exceptions_network_exception_hpp_H_

include/mirai/mirai.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "mirai/defs/defs.hpp"
66
#include "mirai/events/events.hpp"
7+
#include "mirai/exceptions/exceptions.hpp"
78
#include "mirai/mirai_bot.hpp"
89

910
#endif // !mirai_cpp__mirai_h_H_

0 commit comments

Comments
 (0)