提问人:janci 提问时间:10/23/2023 更新时间:10/23/2023 访问量:19
调试器在 catch 语句中显示异常“未处理的用户异常”
Debugger displays an exception "Unhandled user exception" from within catch statement
问:
我让函数抛出一个(由我定义)异常,并且该函数是从方法的 catch 语句中调用的。
当引发异常时,调试器会显示一条消息 - 为什么?getRefreshToken
AppException
RefreshToken
Unhandled user exception
private (RefreshToken, Account) getRefreshToken(string token)
{
var account = _context.Accounts.Include(x => x.RefreshTokens).SingleOrDefault(u => u.RefreshTokens.Any(t => t.Token == token));
//var account = _context.Accounts.SingleOrDefault(u => u.RefreshTokens.Any(t => t.Token == token));
if (account == null)
{
Console.WriteLine("Exception thrown");
throw new AppException("Invalid account for token"+ token);
}
var refreshToken = account.RefreshTokens.Single(x => x.Token == token);
if (!refreshToken.IsActive)
{
Console.WriteLine("Exception thrown");
throw new AppException("Invalid token:"+ token);
}
return (refreshToken, account);
}
带有 catch 语句的调用方函数:
public AuthenticateResponse RefreshToken(string token, string ipAddress)
{
log.Info("RefreshToken before locking");
Monitor.Enter(lockObject);
using (IDbContextTransaction transaction = _context.Database.BeginTransaction())
{
try
{
var (refreshToken, account) = getRefreshToken(token);
}
catch
{
transaction.Rollback();
Console.WriteLine(Thread.CurrentThread.Name + "Error occurred.");
log.Error(Thread.CurrentThread.Name + "Error occurred in RefreshToken:");
throw;
}
finally
{
Monitor.Exit(lockObject);
log.Info("RefreshToken after locking");
}
}
}
答: 暂无答案
评论
AppException
getRefreshToken
catch
RefreshToken
catch
RefreshToken