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.