Solved

C# Error message formatting

Posted on 2014-09-11
3
65 Views
Last Modified: 2016-06-21
we currently have a very convoluted methodology for displaying error messages.  But right now, I would just like to know how to correct one specific message.
The code used to build the message is:
        /// <summary>
        /// Adds the error details.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="errors">The errors.</param>
        private void AddErrorDetails(ref string message, Dictionary<string, string> errors)
        {
            if (errors == null)
            {
                return;
            }

            if (message == null)
            {
                message = string.Empty;
            }

            foreach (string key in errors.Keys)
            {
                if (!string.IsNullOrEmpty(message))
                {
                    message += Environment.NewLine;
                }

                if (key != null)
                {
                    message += errors[key];
                }
            }
        }

Open in new window


the resulting message looks like:

error-msg.png
I would like it to be more like:

Delivery succeeded but with errors. See below for details.
Adjusting stock:  NrfiInd=N, ParentMals UIC = 09107,  Niin = 007345641, Location - Staging......

you get the idea.
Any help would be appreciated.
0
Comment
Question by:PSCTECH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 40318551
Just to clarify, your question is about:
a) How to remove the curly braces regardless of their location?
b) How to remove extra key entry? e.g.  ParentMals={ParentMals UIC = 09107} to  ParentMals UIC = 09107
c) Are the extra keys well known values? (e.g. we can create a list so that we can replace them accordingly)

For (a), you just need to replace the braces with a blank space as follows:
message.Replace("{", " ").Replace("}", " ");

Open in new window



If more help is needed please post errors[key] contents and answer to my questions.
0
 

Author Comment

by:PSCTECH
ID: 40319082
a. worked great, thank you.
b. yes that's how I want it to display
c.  no they are volatile and set at run time

I'm not at the office right now, I will try to get the errors[key] content as soon as I can
0

Featured Post

Get Actionable Data from Your Monitoring Solution

Your communication platform is only as good as the relevance of the information you send. Ensure your alerts get to the right people every time with actionable responses. Create escalation rules that ensure everyone follows the process and nothing is left to chance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question