Solved

Collecting Exceptions

Posted on 2007-03-22
2
276 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
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…

770 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