Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have a windows service project.
it has about 100 methods in it.
each method has its own try and catch block.
I want to send a email to the developers/Maintenance team when ever there is a error in the application.
That email should contain the method name ,line number of error,error message and the variables data for that method(for example 3 variables are declared in a method, I should get all the variables data)
Can I get a simple solution for this one.

Thanks in advance.
Posted
Comments
Sergey Alexandrovich Kryukov 15-Jun-15 15:50pm    
"Each method has its own try and catch block" immediately throws you out of track. This is the utterly wrong approach. The exception can propagate up stack, and you should use it to minimize exception handling and improve reliability of code, remove redundant code, isolate exceptions from "normal" processing. If you catch exception in all methods, there is nothing to discuss. First get rid of such trash. When it's done, try to complete your work and then provide detail explanation of the problems, if you still have any.
—SA

First of all, please see my comment to the question. "Each method has its own try and catch block" is so wrong that you should first address this problem, before doing anything else.

As to the sending of exception report to the developers, it's quite possible and is often used. I have some advise for you:


—SA
 
Share this answer
 
okay,
Thanks for the quick reply,
I have my method something like this.

C#
private int GetLineInformation(string lineNumber) //We have 100 methods like this
    {
       int result = 0;
        try
        {

            return ExecuteExpectionHandledOperation(() =>
            {
                //Implimentation Here
                EventLogtoApp("GetLineId: "+result, EventLogEntryType.Information);
                return result;
            });
        }
        catch (Exception ex)
        {
            EventLogtoApp("Error in GetLineId: " + ex.Message, EventLogEntryType.Error);
        }
        return 0;

    }


I need to get the exception details globally and the variables data(for example result(INT) for this method), used for the methods.
then I can email the details to the development team.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Jun-15 16:08pm    
Wrong!!!
—SA
praneeth arnepalli 16-Jun-15 17:02pm    
I cannot change the code structure right now, as it is a old code, Is there any way that I can achieve my requirement?
all the catch blocks has EventLogtoApp() method,may be can I use this to achieve my requirement ?
Sergey Alexandrovich Kryukov 16-Jun-15 17:13pm    
I answered in detail. It's up to you how much you refactor the code, but I warned you.
You have everything to go forward. Will you accept my answer formally? Any follow-up questions?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900