StrataFrame Forum

StrataFrame Exceptions vs .NET Exceptions

http://forum.strataframe.net/Topic31891.aspx

By William Fields - 3/1/2013

Hello,

I'm a begginer StrataFrame developer and am interested in what benefit I would get out of using the StrataFrame Exception class over just the base .NET exception class.

I have a console app that has a very basic try/catch error handler where an exception is entered into the Windows EventLog like this:

l_ovCalLog.WriteEntry(l_oException.ToString(), EventLogEntryType.Error)

Which is fine for what I'm using it for, but I'm interested in what StrataFrame tools/classes I can use for my benefit outside of a normal Winforms app.
By StrataFrame Team - 3/1/2013

You can throw any exception you want.  According to Microsoft's guidelines, they used to say that you should base any exceptions you create off of ApplicationException.  It's the base class for almost every exception in the .NET Framework.  But they have now changed their mind:

About halfway down this article:

http://msdn.microsoft.com/en-us/library/vstudio/seyhszts(v=vs.100).aspx
For most applications, derive custom exceptions from the Exception class. It was originally thought that custom exceptions should derive from the ApplicationException class; however in practice this has not been found to add significant value.
You can throw StrataFrameExceptions if you want.  We don't add any extra features to the StrataFrameException class.  We created it and the BusinessLayerException and DataLayerException classes in order to wrap common exceptions and give more information that a developer can use to solve the problem.  Most of it is configuration-related stuff.  For instance, if you try to run a query without first adding a DataSource to the DataBasics.DataSources collection, we don't just throw a KeyNotFoundException from .NET, we wrap it and say "hey, you need to add a data source before you try this."

Now, the StrataFrameException class doesn't add anything extra, but we have some exception helpers that are useful.  We have the MicroFour.StrataFrame.Tools.Exceptions class.  The most useful method on it is the CreateExceptionDetails() method which returns a string that lists all of the inner exceptions and a combined stack trace of all of the inner exceptions.  It also includes extra information on common exceptions like TypeLoadExceptions and such that have extra details in there internal IList stuff.

We also have the MicroFour.StrataFrame.Application.ApplicationErrorDialog which shows an exception using the CreateExceptionDetails() method mentioned above in a nice, red box.

The default project template also adds handlers to AppDomain.Current.UnhandledException to trap exceptions that are, you guessed it, unhandled.

Hope that helps.