Mark Gilbert's Blog

Science and technology, served light and fluffy.

Nearly Sentient Error Messages

I’ve been working with Castle ActiveRecord for a “home” project for much of the last year.  With one notable exception (which I intend to blog about in the near future), I love the framework and the functionality it provides.

One particular area where ActiveRecord excels is its error messages.  Not only are the messages detailed, but the ones that I’ve come across also tend to give you hints as to what you may have forgotten to do.  Take this one, for example:

Castle.ActiveRecord.Framework.ActiveRecordException : You have accessed an ActiveRecord class that wasn’t properly initialized. The only explanation is that the call to ActiveRecordStarter.Initialize() didn’t include BMSBusinessServices.SKUDate class.

Before you can use an ActiveRecord class, you have to initialize it.  For desktop apps like mine, the call to ActiveRecordStarter.Initialize() is made in the MDI Parent form’s constructor, one of the first things to execute when the app loads (for web apps you’d place this call in the Application_Init event, defined in Global.asax).  The Initialize() method takes a list of the classes that you want to designate as being visible to ActiveRecord.  The error message above points you in that direction.

Now, as it turns out, I did have the SKUDate class listed in the Initialize method, so I had to dig a little deeper for the solution, which I found in this post: http://www.feed-squirrel.com/index.cfm?evt=viewItem&ID=69310.  The post is a little hard to read (any and all whitespace between sentences and paragraphs appeared to be stripped out), but near the very end the post mentions that this error can also be caused when you forget to decorate the class in question with the <ActiveRecord()> attribute.

Which I had.

And once I added it everything was happy again.

Despite the fact that the error didn’t point to the real solution to my problem, what it did give showed me what an exception could really be.  After seeing this particular message, I felt compelled to take a long hard look at the custom exceptions that I write and the messages that they include. Basically, my exceptions needed to grow up a little and become slightly more intelligent.

Advertisements

January 4, 2010 - Posted by | Castle ActiveRecord, Visual Studio/.NET

1 Comment

  1. […] 2010 Posted by markegilbert in Castle ActiveRecord, Visual Studio/.NET. trackback I mentioned a couple of weeks ago that other than one notable exception, I was loving Castle ActiveRecord.  That one exception […]

    Pingback by Join me, and together we’ll rule… – ActiveRecord and Attributes on Join Classes « Mark Gilbert’s Blog | January 21, 2010


Sorry, the comment form is closed at this time.

%d bloggers like this: