Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8779423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:46:58+00:00 2026-06-13T19:46:58+00:00

I’m trying to load an xml file into the interface and there may be

  • 0

I’m trying to load an xml file into the interface and there may be many exceptions based on data in Xml file, So I want to catch all the exceptions at once.
I got around 15 exceptions and display it once RichTextBox or Something else or in a MessageBox.

for (int i = 0; i < this.SortedLaneConfigs.Count; i++)
    {
         if(this.SortedLaneConfigs[i].CheckConsistency())
            {
                throw new DataConsistencyException(String.Format("Lane #{0} NOT consistent : {1}", i, e.Message)
            }
    }


if (this.SortedLaneConfigs[i - 1].EndB > this.SortedConfigs[i].BeginB)
    {
        throw new DataConsistencyException(String.Format("Lanes {0} & {1}  overlap", i - 1, i));
    }

    this.SortedLaneConfigs.ForEach(
        laneConfig =>
        {
            if (this.SortedLaneConfigs.FindAll(item => item.Id == laneConfig.Id).Count != 1)
                {
                    new DataConsistencyException(String.Format("Id \"{0}\" present more than once", laneConfig.Id));
                }
        });

I know, I can catch exception and display it in a message box, in this normal way.

 try
    {
         this.SortedLaneConfigs[i].CheckConsistency();
    }
catch (Exception e)
    {
        MessageBox.Show("Error message below: \n\"" + String.Format("Configs #{0} NOT consistent : {1}", SortedLaneConfigs[i].Id, e.Message) + "\"", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }

I googled it and i found these 2 links, link1:http://blogs.elangovanr.com/post/Catch-multiple-Exceptions-together-in-C.aspx link2:
Catch multiple exceptions at once?

How can i adapt the suggested solution from those two links to display all the exceptions at once in RichTextBox or or Something else or in a messageBox. Please help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:46:59+00:00Added an answer on June 13, 2026 at 7:46 pm

    You can concatenate the Exception.Message strings and display them wherever you like:
    First create StringBuilder instance before you enter your method(s):

    StringBuilder exBuilder = new StringBuilder();
    

    Then execute your method(s) and append exceptions messages:

    try
    {
             this.SortedLaneConfigs[i].CheckConsistency();
    }
    catch (Exception e)
    {
            exBuilder.Append("Error message below: \n\"" + String.Format("Configs #{0} NOT consistent : {1}", SortedLaneConfigs[i].Id, e.Message) + "\"");
            exBuilder.Append(Environment.NewLine);
    }
    

    And after you finish you can get the string with exBuilder.ToString();

    richTextBox1.Text = exBuilder.ToString();
    

    EDIT:
    Suppose that you have a Form which has RichTextbox and Button on it. If the Button initiates your methods, then the use case can be like this:

    public partial class Form1 : Form
    {
            StringBuilder exBuilder;
            public Form2()
            {
                InitializeComponent();
                exBuilder = new StringBuilder();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                exBuilder.Clear();
                MyMethod();
                //and all your other methods that have exBuilder.Append in their try-catch blocks
                richTextBox1.Text = exBuilder.ToString();
            }
    
            void MyMethod()
            {
                try
                {
                    //you code or whatever
                }
                catch(Exception e)
                {
                    exBuilder.Append("Error message below: \n\"" + String.Format("Configs #{0} NOT consistent : {1}", parameter, e.Message) + "\"" + Environment.NewLine);
                }
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I want to construct a data frame in an Rcpp function, but when I
I'm parsing an XML file, the creators of it stuck in a bunch social
i want to parse a xhtml file and display in UITableView. what is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.