public bool TranslateException(Exception exception, out string message, out Exception newException) { message = exception.Message; newException = exception; if (exception is ProviderIncompatibleException) { message = Strings.DbConnectionError; return(true); } if (exception is EntityCommandExecutionException) { message = Strings.DbCommandExecutionError; return(true); } if (exception is DbEntityValidationException) { ValidationRuleViolations violations = new ValidationRuleViolations(); violations.Add((exception as DbEntityValidationException).EntityValidationErrors); message = Strings.DbValidationError; newException = new DbWrappedException(message, exception, violations); return(true); } if (exception is DbUpdateException || exception is SqlException) { message = Strings.DbUpdateError; newException = ExceptionUtils.GetInnerException(exception); foreach (var regex in Strings.ConstraintRegexes) { if (regex.IsMatch(newException.Message)) { string constraintName = regex.Matches(newException.Message)[0].Groups["cName"].ToString(); string constraintMessage = GetConstraintMessage(constraintName); if (constraintMessage != null) { message = constraintMessage; } } } return(true); } return(false); }
public bool TranslateException(Exception exception, out string message, out Exception newException) { message = exception.Message; newException = exception; if (exception is ProviderIncompatibleException) { message = Strings.DbConnectionError; return true; } if (exception is EntityCommandExecutionException) { message = Strings.DbCommandExecutionError; return true; } if (exception is DbEntityValidationException) { ValidationRuleViolations violations = new ValidationRuleViolations(); violations.Add((exception as DbEntityValidationException).EntityValidationErrors); message = Strings.DbValidationError; newException = new DbWrappedException(message, exception, violations); return true; } if (exception is DbUpdateException || exception is SqlException) { message = Strings.DbUpdateError; newException = ExceptionUtils.GetInnerException(exception); if (exception is SqlException) { foreach (var regex in Strings.ConstraintRegexes) { if (regex.IsMatch(newException.Message)) { string constraintName = regex.Matches(exception.Message)[0].Groups["cName"].ToString(); string constraintMessage = GetConstraintMessage(constraintName); if (message != null) { message = constraintMessage; } } } } return true; } return false; }
public ValidationRuleException(ValidationRuleViolations violations) : base(Strings.ThereAreValidationErrors) { this.violations = violations; }