Red Gate forums :: View topic - ExceptionReporting.Report(ex) Missing Local Var/Stack Trace
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SmartAssembly 6
SmartAssembly 6 forum

ExceptionReporting.Report(ex) Missing Local Var/Stack Trace

Search in SmartAssembly 6 forum
Post new topic   Reply to topic
Jump to:  
Author Message
memeDeveloper



Joined: 22 Jun 2012
Posts: 17

PostPosted: Wed Jul 11, 2012 7:01 pm    Post subject: ExceptionReporting.Report(ex) Missing Local Var/Stack Trace Reply with quote

Hi,

I am trying to report exceptions to smart assembly. I have a method in my application which is called whenever an exception occur. I want to add error reporting in that method. I have used this ExceptionReporting.Report(ex) in my method. Now, whenever I want to report some exception or any other exception is thrown that method gets called and it has that line of code. However, in the reports , the local variables and the stack trace are missing. In the wiki page of the SDK this is mentioned at the end of the page in the Misc section regarding my situation:

"If you want to manually send an exception to SmartAssembly's UnhandledExceptionHandler, you may use the method:

SmartAssembly.ReportException.ExceptionReporting.Report(System.Exception exception)

Note that the local variables and the stack trace are missing for the method which called Report. A workaround is to wrap the whole method up in a delegate or empty method."

Can someone show me an example for this workaround ?
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6589

PostPosted: Thu Jul 12, 2012 1:22 pm    Post subject: Reply with quote

Hello,

The first method is pretty self-explanatory. Create a new method and call the original method from it. If you are building a DLL, you may want to rename the methods so the entry point names are preserved.
Code:

DoSomething()
{
     OriginalDoSomething();
}
OriginalDoSomething()
{
    try {
       Something();
          }
    catch (Exception exc)
          {
              ExceptionReporting.Report(exc);
           }
}

EDIT: The above solution has been proven not to work.
Solution number 2 involves creating a delegate:
Code:

using System;
using SmartAssembly.ReportException;

namespace delegateexample
{
    class Program
    {
        static void Main(string[] args)
        {
            ErrorHandling.DoWithErrorHandling(delegate
            {
                OriginalDoSomething();
            }
            );
            Console.ReadLine();
        }

        private static void OriginalDoSomething()
        {
            /* your original code */
        }
    }
    // Delegate needs to be typed for DoWithErrorHandling...
    public delegate void DoSomethingDelegate();
    /// <summary>
    /// This class will invoke the code specified in the delegate and report exceptions to SA
    /// </summary>
   
    class ErrorHandling
        {
            public static void DoWithErrorHandling(DoSomethingDelegate toDo)
            {
                try
                {
                    toDo();
                }
                catch (Exception e)
                {
                    ExceptionReporting.Report(e);
                }
            }
        }
}

In this way, you create a new class to invoke the code and trap any errors. You can wrap any code for which you want to report exceptions into the DoWithErrorHandling method.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group