Always continue after an exception

MarcoMarco Posts: 19
edited July 21, 2010 11:34AM in SmartAssembly 5
Hi
I have a trial version of SmartAssembly 5.1. I'm testing the "Automated Error Reporting". The problem is the setting "Always continue after an exception", because it doesn't work. After sending the error report, my program will close. I use the standard template.

Thanks
Marco

Comments

  • Brian DonahueBrian Donahue Posts: 6,590 New member
    Hi Marco,

    Am I right in assuming that certain types of .NET Runtime exceptions will not let a program continue, no matter what?

    SmartAssembly's description of this feature is carefully-worded (it will attempt to continue).
  • Hi Brian,

    Do you have a list of exceptions that my program will close and which not?
    Can I control, which exceptions will close my program?

    You attach to each method and property following code:
    try
    {
    //MyCode
    }
    catch (Exception exception1)
    {
    UnhandledException.CreateExceptionX();
    throw;
    }
    Is there a way to omit the "throw;"?

    Thanks
    Marco
  • Paul.MartinPaul.Martin Posts: 83 New member
    Any non-recoverable exception will stop the application from continuing (as defined by the framework) - so ExecutionEngineException, StackOverflowException, and OutOfMemoryException.

    Also if the exception occurs within the assembly's entry point then you wont be able to continue.


    Unfortunately it is not possible to specify in the UI which exceptions to continue from. However, if you have the Pro version of SmartAssembly it is very easy to customise the error reporting template and add a little bit of logic which changes the value of ReportExceptionEventArgs.tryToContinue (as passed to OnReportException) depending on the exception type.


    The throw is required unless you apply the ReportExceptionAttribute to the methods (which mean the exception is caught, reported but not propagated). SmartAssembly is designed to preserve the exception handling semantics of your code so that if you have your own try/catch block for a particular exception SmartAssembly will not interfere with it, for this reason the exception is left to propagate until nothing else handles it.
  • Hi

    I have tested OverflowException, ArgumentNullException and DivideByZeroException. Unfortunately my program is always closed. If I use the ReportExceptionAttribute, then my program is not closed.
    What is the problem?

    Thanks
    Marco
  • Paul.MartinPaul.Martin Posts: 83 New member
    What type of application are your protecting?

    Are you doing any global error handling yourself?
  • I'm protecting a WPF application written in C#. I don't have any global error handling.
  • Hi
    I have changed my test project to a Windows Forms Application and now everything works. However, this is not the solution, as we work with WPF.

    Thanks
    Marco
  • Paul.MartinPaul.Martin Posts: 83 New member
    Ah, I've done a bit of digging and that is a bug.
    WPF has an extra unhandled exception event in the framework to WinForms. The events common between WPF and WinForms will work on WPF, however, in WPF they are both raised at a point where the application can't continue (it is possible to continue when the extra event in WPF is raised).

    I've logged a bug in our tracking system (SA-376) for our developers to fix.

    The only workarounds I can suggest in the meantime is either use the "ReportExceptionAttribute" on every method (which I know would be a real pain), or if you buy the Pro version you just need to add a handler for the missing event:

    Somewhere near the start of your application add a line:
    System.Windows.Threading.Dispatcher.CurrentDispatcher.UnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
    

    and then add the method to handle the event
    void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
            {
                e.Handled = true;
    
                SmartAssembly.ReportException.ExceptionReporting.Report(e.Exception);
            }
    

    (note you do need the Pro edition as the SDK, which ReportException.ExceptionReporting is part of, requires the Pro edition or Team package)
Sign In or Register to comment.