Always continue after an exception

.NET obfuscator and automated error reporting

Moderators: Luke Jefferson, Alex.Davies, melvyn.harbour

Always continue after an exception

Postby Marco » Fri Jul 16, 2010 4:00 pm

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
Marco
 
Posts: 12
Joined: Fri Jul 16, 2010 3:57 pm

Postby Brian Donahue » Fri Jul 16, 2010 4:15 pm

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).
Brian Donahue
 
Posts: 6670
Joined: Mon Aug 23, 2004 10:48 am

Postby Marco » Mon Jul 19, 2010 8:26 am

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
Marco
 
Posts: 12
Joined: Fri Jul 16, 2010 3:57 pm

Postby Paul.Martin » Mon Jul 19, 2010 11:13 am

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.
Paul.Martin
 
Posts: 83
Joined: Wed Feb 03, 2010 11:20 am
Location: Cambridgeshire

Postby Marco » Mon Jul 19, 2010 5:24 pm

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
Marco
 
Posts: 12
Joined: Fri Jul 16, 2010 3:57 pm

Postby Paul.Martin » Mon Jul 19, 2010 5:27 pm

What type of application are your protecting?

Are you doing any global error handling yourself?
Paul.Martin
 
Posts: 83
Joined: Wed Feb 03, 2010 11:20 am
Location: Cambridgeshire

Postby Marco » Mon Jul 19, 2010 7:17 pm

I'm protecting a WPF application written in C#. I don't have any global error handling.
Marco
 
Posts: 12
Joined: Fri Jul 16, 2010 3:57 pm

Postby Marco » Tue Jul 20, 2010 8:42 am

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
Marco
 
Posts: 12
Joined: Fri Jul 16, 2010 3:57 pm

Postby Paul.Martin » Wed Jul 21, 2010 4:34 pm

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:
Code: Select all
System.Windows.Threading.Dispatcher.CurrentDispatcher.UnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);


and then add the method to handle the event
Code: Select all
        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)
Paul.Martin
 
Posts: 83
Joined: Wed Feb 03, 2010 11:20 am
Location: Cambridgeshire


Return to SmartAssembly 5

Who is online

Users browsing this forum: No registered users and 1 guest