第二个尝试捕获中的相同异常“插入语句与外键约束冲突”

时间:2018-06-26 11:03:50

标签: c# asp.net linq

[Route("API/Add")]

[HttpPost]
public GenericClasss AddData(CAddData_Request Data)
{
        GenericClasss Obj = new GenericClasss();

        try
        {
            Obj = _Base.AddDataa(Data);                   
        }
        catch (System.Exception ex)
        {
            string JsonData = _Base.ConvertJsontoString(Data);
            _Base.ServiceLogException(ex, ActionContext.ActionDescriptor.ActionName, JsonData);
        }

        return Obj;
    }    
}

public void ServiceLogException(System.Exception ex, string MethodName, string Data)
{
    try
    {
        AppException _Exception = new AppException();
        _Exception.Employee_ID = null;
        _Exception.Method = MethodName;
        _Exception.Page = "";
        _Exception.Line = ex == null ? "0" : Convert.ToString(new System.Diagnostics.StackTrace(ex, true).GetFrame(0).GetFileLineNumber());
        _Exception.Object = Data;
        _Exception.Message = ex == null ? null : ex.Message;
        _Exception.CreatedDate = System.DateTime.UtcNow;
        _Exception.ExceptionType = 2;
        _Exception.IsSolved = false;

        DB.AppExceptions.Add(_Exception);
        DB.SaveChanges();
    }
    catch (Exception exa)
    {
    }
}

问题:

如果AddData方法生成异常

  

插入语句与外键约束冲突

然后将其转到catch块并将异常条目插入数据库中。

但是我的ServiceLogException方法也会生成相同的异常

  

插入语句与外键约束冲突

0 个答案:

没有答案