Red Gate forums :: View topic - Always continue after an exception
Return to www.red-gate.com RSS Feed Available

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

Always continue after an exception

Search in SmartAssembly 5 forum
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.
Jump to:  
Author Message
Marco



Joined: 16 Jul 2010
Posts: 12

PostPosted: Fri Jul 16, 2010 4:00 pm    Post subject: Always continue after an exception Reply with quote

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
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6646

PostPosted: Fri Jul 16, 2010 4:15 pm    Post subject: Reply with quote

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).
Back to top
View user's profile Send private message
Marco



Joined: 16 Jul 2010
Posts: 12

PostPosted: Mon Jul 19, 2010 8:26 am    Post subject: Reply with quote

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
View user's profile Send private message
Paul.Martin



Joined: 03 Feb 2010
Posts: 83
Location: Cambridgeshire

PostPosted: Mon Jul 19, 2010 11:13 am    Post subject: Reply with quote

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
View user's profile Send private message
Marco



Joined: 16 Jul 2010
Posts: 12

PostPosted: Mon Jul 19, 2010 5:24 pm    Post subject: Reply with quote

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
View user's profile Send private message
Paul.Martin



Joined: 03 Feb 2010
Posts: 83
Location: Cambridgeshire

PostPosted: Mon Jul 19, 2010 5:27 pm    Post subject: Reply with quote

What type of application are your protecting?

Are you doing any global error handling yourself?
Back to top
View user's profile Send private message
Marco



Joined: 16 Jul 2010
Posts: 12

PostPosted: Mon Jul 19, 2010 7:17 pm    Post subject: Reply with quote

I'm protecting a WPF application written in C#. I don't have any global error handling.
Back to top
View user's profile Send private message
Marco



Joined: 16 Jul 2010
Posts: 12

PostPosted: Tue Jul 20, 2010 8:42 am    Post subject: Reply with quote

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
View user's profile Send private message
Paul.Martin



Joined: 03 Feb 2010
Posts: 83
Location: Cambridgeshire

PostPosted: Wed Jul 21, 2010 4:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This topic is locked: you cannot edit posts or make replies. 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