| Author |
Message |
Marco
Joined: 16 Jul 2010 Posts: 12
|
Posted: Fri Jul 16, 2010 4:00 pm Post subject: Always continue after an exception |
|
|
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 |
|
| Back to top |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6369 Location: Red Gate Software
|
Posted: Fri Jul 16, 2010 4:15 pm Post subject: |
|
|
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
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
Marco
Joined: 16 Jul 2010 Posts: 12
|
Posted: Mon Jul 19, 2010 8:26 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Paul.Martin
Joined: 03 Feb 2010 Posts: 83 Location: Cambridgeshire
|
Posted: Mon Jul 19, 2010 11:13 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Marco
Joined: 16 Jul 2010 Posts: 12
|
Posted: Mon Jul 19, 2010 5:24 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Paul.Martin
Joined: 03 Feb 2010 Posts: 83 Location: Cambridgeshire
|
Posted: Mon Jul 19, 2010 5:27 pm Post subject: |
|
|
What type of application are your protecting?
Are you doing any global error handling yourself? |
|
| Back to top |
|
 |
Marco
Joined: 16 Jul 2010 Posts: 12
|
Posted: Mon Jul 19, 2010 7:17 pm Post subject: |
|
|
| I'm protecting a WPF application written in C#. I don't have any global error handling. |
|
| Back to top |
|
 |
Marco
Joined: 16 Jul 2010 Posts: 12
|
Posted: Tue Jul 20, 2010 8:42 am Post subject: |
|
|
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 |
|
| Back to top |
|
 |
Paul.Martin
Joined: 03 Feb 2010 Posts: 83 Location: Cambridgeshire
|
Posted: Wed Jul 21, 2010 4:34 pm Post subject: |
|
|
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: |
| System.Windows.Threading.Dispatcher.CurrentDispatcher.UnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException); |
and then add the method to handle the event
| Code: |
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) |
|
| Back to top |
|
 |
|