<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Error Handling</Title>
      <Shortcut>ErrorHandling</Shortcut>
      <Description>Error Handling [C#]</Description>
      <Author>Bhavesh Patel</Author>
      <HelpUrl>/PreviewSnippet.aspx?SnippetID=9ef6ea8c-42a4-4688-92c7-77dd4d833889</HelpUrl>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="csharp"><![CDATA[private void DisplayExceptionDetails(Exception ex) { // Display a user-friendly message ExceptionDetails.Text = "There was a problem updating the product. "; if (ex is System.Data.Common.DbException) ExceptionDetails.Text += "Our database is currently experiencing problems. Please try again later."; else if (ex is NoNullAllowedException) ExceptionDetails.Text += "There are one or more required fields that are missing."; else if (ex is ArgumentException) { string paramName = ((ArgumentException)ex).ParamName; ExceptionDetails.Text += string.Concat("The ", paramName, " value is illegal."); } else if (ex is ApplicationException) ExceptionDetails.Text += ex.Message; }]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>