-1

I want to consolidate all exceptions. Is this a good practice to do so?

 string consolidatingAllException = string.Empty;
            try
            {
                // some process();
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    consolidatingAllException += (ex.InnerException.Message);
                }
            }
Pratik
  • 11,534
  • 22
  • 69
  • 99
  • This isn't even your question but you need to do `while (ex != null) { exceptionString += ex.Message; ex = ex.InnerException; }`; your code as posted is just an infinite loop if there's at least one inner exception. – Quantic Sep 08 '16 at 18:42
  • Why not a `List`? – Pau C Sep 08 '16 at 18:46
  • What are your requirements? Did you have a look at the [Enterprise Library Exception Handling](https://msdn.microsoft.com/en-us/library/dd203116.aspx) block? – Jeroen Heier Sep 08 '16 at 18:48

1 Answers1

1

If you plan to log all your exceptions together for historic reasons or reviewing them later I suggest using Trace Listener Just trace the exceptions in catch and log them using Trace.TraceInformation() and eventually flush them into a log file

pank
  • 11
  • 2