记录最后一次发生的异常

This commit is contained in:
milimoe 2026-05-11 19:54:02 +08:00
parent 2b3ff5770d
commit 1598eef40b
Signed by: milimoe
GPG Key ID: 9554D37E4B8991D0
2 changed files with 26 additions and 0 deletions

View File

@ -60,6 +60,11 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
/// </summary>
public override DataSet DataSet => _dataSet;
/// <summary>
/// 最后一次执行命令时发生的异常
/// </summary>
public override Exception? LastException => _lastException;
/// <summary>
/// SQL 语句参数
/// </summary>
@ -73,6 +78,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
private readonly SQLServerInfo? _serverInfo;
private int _affectedRows = 0;
private long _lastInsertId = 0;
private Exception? _lastException = null;
public MySQLHelper(string script = "", CommandType type = CommandType.Text)
{
@ -167,6 +173,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
if (localTransaction) Rollback();
_result = SQLResult.SQLError;
ServerHelper.Error(e);
@ -231,6 +238,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
if (localTransaction) Rollback();
_result = SQLResult.SQLError;
ServerHelper.Error(e);
@ -295,6 +303,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
if (localTransaction) Rollback();
_result = SQLResult.SQLError;
ServerHelper.Error(e);
@ -359,6 +368,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
if (localTransaction) Rollback();
_result = SQLResult.SQLError;
ServerHelper.Error(e);
@ -395,6 +405,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
_result = SQLResult.SQLError;
ServerHelper.Error(e);
}
@ -416,6 +427,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
_result = SQLResult.SQLError;
ServerHelper.Error(e);
}
@ -438,6 +450,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
ServerHelper.Error(e);
_result = SQLResult.SQLError;
return false;

View File

@ -60,6 +60,11 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
/// </summary>
public override DataSet DataSet => _dataSet;
/// <summary>
/// 最后一次执行命令时发生的异常
/// </summary>
public override Exception? LastException => _lastException;
/// <summary>
/// SQL 语句参数
/// </summary>
@ -73,6 +78,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
private readonly SQLServerInfo? _serverInfo;
private int _affectedRows = 0;
private long _lastInsertId = 0;
private Exception? _lastException = null;
public SQLiteHelper(string script = "", CommandType type = CommandType.Text)
{
@ -167,6 +173,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
if (localTransaction) Rollback();
_result = SQLResult.SQLError;
ServerHelper.Error(e);
@ -233,6 +240,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
if (localTransaction) Rollback();
_result = SQLResult.SQLError;
ServerHelper.Error(e);
@ -298,6 +306,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
if (localTransaction) Rollback();
_result = SQLResult.SQLError;
ServerHelper.Error(e);
@ -363,6 +372,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
if (localTransaction) Rollback();
_result = SQLResult.SQLError;
ServerHelper.Error(e);
@ -399,6 +409,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
_result = SQLResult.SQLError;
ServerHelper.Error(e);
}
@ -420,6 +431,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
_result = SQLResult.SQLError;
ServerHelper.Error(e);
}
@ -442,6 +454,7 @@ namespace Milimoe.FunGame.Server.Services.DataUtility
}
catch (Exception e)
{
_lastException = e;
ServerHelper.Error(e);
_result = SQLResult.SQLError;
return false;