Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Exception handling
Message
 
 
À
Tous
Information générale
Forum:
C#
Catégorie:
Code, syntaxe and commandes
Titre:
Exception handling
Divers
Thread ID:
01651425
Message ID:
01651425
Vues:
58
Hi everybody,

I checked this https://stackoverflow.com/questions/1456563/best-way-to-check-for-inner-exception
.
We have the following code:
var sqlException = GetSqlExceptionFromBaseException(ex);
            if (sqlException != null)
            {
                //2627 is the exception number for a unique constraint violation
                if (sqlException.Number == 2627)
                {
                    var errorMessage = Messages.alreadyExists;
                    var sentences = sqlException.Message.Split('.');
                    var duplicateValue = Regex.Matches(sqlException.Message, @"\(([^)]*)\)");
                    if (sentences.Count() > 3  && duplicateValue.Count > 0)
                    {                        
                        errorMessage =
                            String.Format(Messages.alreadyExistsWithValue, duplicateValue[0].Value.Replace("(", "").Replace(")", ""));
                    }
                    throw new DuplicatePropertyException(errorMessage);
                }
                else
                {
                    throw ex;
                }
            }
            else
            {
                throw ex;
            }
        }
The exception actually says check inner exception for details (and I can see the actual exception when I do so). I'm wondering what is the best way to throw this error but at the same time present that inner exception text as well?

We do log it properly with Elmah but I also want to display it instead of 'see inner exception' message.

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform