I have an application using .net entity framework I am trying to debug. It would be much simpler if I could put a catch attempt in C # code around .SaveChanges () objects and be able to distinguish between errors that occur due to malfunctioning sql scripts and other errors. I was wondering if anyone knows if this is possible / how to do it.
eg,
try{
entities.SaveChanges();
}Catch(Exception e){
if(e is MysterySqlTriggerException){
//do something
}else{
//do something else
}
}
/ ** Edit ** /
Below is the final recursive method that I used to handle this
public void HandleTriggerException(Exception e)
{
if (e is SqlException)
{
SqlException sqlException = (SqlException)e;
if (sqlException.Procedure.Contains("tr_"))
{
}
}
if (e.InnerException != null)
{
HandleTriggerException(e.InnerException);
}
}
source
share