fix:修复前端bug (#83)
Co-authored-by: jackfiled <xcrenchangjun@outlook.com> Reviewed-on: PostGuard/Canon#83 Co-authored-by: ichirinko <1621543655@qq.com> Co-committed-by: ichirinko <1621543655@qq.com>
This commit is contained in:
19
Canon.Core/Exceptions/CanonException.cs
Normal file
19
Canon.Core/Exceptions/CanonException.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace Canon.Core.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// 编译器中的统一异常基类
|
||||
/// </summary>
|
||||
public class CanonException : Exception
|
||||
{
|
||||
public CanonException()
|
||||
{
|
||||
}
|
||||
|
||||
public CanonException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public CanonException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
@@ -8,7 +8,7 @@ namespace Canon.Core.Exceptions;
|
||||
/// <summary>
|
||||
/// 语法分析中引发的异常
|
||||
/// </summary>
|
||||
public class GrammarException : Exception
|
||||
public class GrammarException : CanonException
|
||||
{
|
||||
public override string Message { get; }
|
||||
|
||||
|
@@ -3,32 +3,32 @@ using Enums;
|
||||
/// <summary>
|
||||
/// 词法分析中引发的异常
|
||||
/// </summary>
|
||||
public class LexemeException : Exception
|
||||
public class LexemeException : CanonException
|
||||
{
|
||||
public LexemeErrorType ErrorType { get; }
|
||||
|
||||
public uint Line { get; }
|
||||
|
||||
public uint CharPosition { get; }
|
||||
public LexemeException() { }
|
||||
|
||||
public LexemeException(string message) : base(message) { }
|
||||
|
||||
public LexemeException(string message, Exception innerException) :
|
||||
base(message, innerException) { }
|
||||
private readonly string _message;
|
||||
|
||||
/// <param name="errorType">错误类型</param>
|
||||
/// <param name="line">单词的行号</param>
|
||||
/// <param name="charPosition">单词的列号</param>
|
||||
/// <param name="message">错误信息</param>
|
||||
public LexemeException(LexemeErrorType errorType, uint line, uint charPosition, string message) :
|
||||
base("line:" + line + ", charPosition:" + charPosition + " :" + message)
|
||||
public LexemeException(LexemeErrorType errorType, uint line, uint charPosition, string message)
|
||||
{
|
||||
ErrorType = errorType;
|
||||
Line = line;
|
||||
CharPosition = charPosition;
|
||||
_message = message;
|
||||
}
|
||||
|
||||
public override string Message => ToString();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"LexemeException: ErrorType={ErrorType}, Line={Line}, CharPosition={CharPosition}, Message={Message}\n";
|
||||
return $"LexemeException: ErrorType={ErrorType}, Line={Line}, CharPosition={CharPosition}, Message={_message}\n";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user