PSO2SERVER/Server/Protocol/PacketError.cs

77 lines
2.9 KiB
C#
Raw Normal View History

2024-12-11 04:15:40 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PSO2SERVER.Protocol
{
public class PacketError : Exception
{
public string PacketName { get; }
public string FieldName { get; }
public long ConstantValue { get; }
public Exception InnerError { get; }
// 构造函数: 读取/写入字段失败
public PacketError(string packetName, string fieldName, Exception error)
: base($"读取/写入字段 {fieldName} 来自 {packetName} 时发生错误: {error.Message}", error)
{
PacketName = packetName;
FieldName = fieldName;
InnerError = error;
}
// 构造函数: 读取/写入标志或枚举值失败
public PacketError(string packetName, Exception error)
: base($"读取/写入 {packetName} 的值时发生错误: {error.Message}", error)
{
PacketName = packetName;
InnerError = error;
}
// 构造函数: 读取/写入字段长度失败
public PacketError(string packetName, string fieldName, Exception error, bool isFieldLengthError)
: base($"读取/写入字段 {fieldName} 来自 {packetName} 的长度时发生错误: {error.Message}", error)
{
PacketName = packetName;
FieldName = fieldName;
InnerError = error;
}
// 构造函数: 读取/写入组合字段失败
public PacketError(string packetName, string fieldName, PacketError innerError)
: base($"读取/写入组合字段 {fieldName} 来自 {packetName} 时发生错误: {innerError.Message}", innerError)
{
PacketName = packetName;
FieldName = fieldName;
InnerError = innerError;
}
// 构造函数: 填充字段时发生错误
public PacketError(string packetName, string fieldName, Exception error, int isPaddingError)
: base($"填充字段 {fieldName} 来自 {packetName} 时发生错误: {error.Message}", error)
{
PacketName = packetName;
FieldName = fieldName;
InnerError = error;
}
// 构造函数: 读取/写入常量值时发生错误
public PacketError(string packetName, long constantValue, Exception error)
: base($"读取/写入常量 {constantValue} 来自 {packetName} 时发生错误: {error.Message}", error)
{
PacketName = packetName;
ConstantValue = constantValue;
InnerError = error;
}
// 构造函数: 读取/写入数据包长度时发生错误
public PacketError(Exception error)
: base($"读取/写入数据包长度时发生错误: {error.Message}", error)
{
InnerError = error;
}
}
}