Solved

Collecting Exceptions

Posted on 2007-03-22
2
284 Views
Last Modified: 2010-04-16
Hello
I was told that there is a way to collect exceptions ( Try/Catch )  as I'm running my application without creating a Namespace level string and adding Exception error messages to it.
I have a lot of various Try/Catch blocks in various Classes/Methods in different parts of my program. I need to be able to collect them all and then output in the Log file.

Any help would be much appreciated.
0
Comment
Question by:compulaw
2 Comments
 
LVL 2

Accepted Solution

by:
_Eyeball_ earned 250 total points
ID: 18774090
i would do it the following way:

public static class ErrorCollector
    {
        private static List<System.Exception> m_ErrorList =
            new List<Exception>();

        public static void WriteError(System.Exception ex)
        {
            m_ErrorList.Add(ex);
        }


        public static void WriteLog(string path)
        {
            // Write Log
            m_ErrorList = new List<Exception>();
        }      
    }

This class could be used from everywhere as long your are in the same assembly!

I hope that's what u mean!

best regards
0
 

Author Comment

by:compulaw
ID: 18776267
That could definately work but I don't want to create extra classes/Methods for this.
I believe I'm talking about throwing exceptions...something like:

try
{}
catch(Exception ex)
{
throw new Exception=.. something
}

so this way I collect exceptions and then i can optupid them in some other part of the program. I'm not 100% sure what I'm talking about here... help :)
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

829 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