CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jeremy D. Miller -- The Shade Tree Developer

Under the hood and working with .Net, TDD, Software Design, and Agile Stuff

A Stupid Way to do Error Management

This is obviously a rant, so buckle up.

I'm at the tail end of a little project adding some customizations to a legacy system.  There isn't anything resembling a service (or business/domain) layer other than T-SQL SPROC's, and the vast majority of the business and validation logic is in the stored procedures.  The clown that wrote a great deal of the original system (since departed) had a serious T-SQL fetish.  The guy apparently truly believed that T-SQL was simpler and easier to maintain than C#.  One of the results of this is that validation warnings like "Vendor does not exist" are created and generated by a stored procedure and passed back to the application by the message in the SqlException that's thrown by the command execution.  Whatever is in the body of the exception, or any exception thrown for that matter, is automatically put into the audit tables where it is displayed to the end users on a web page.  Mr. User, you ask why didn't your invoice go through?  Because of "Object reference not set to an instance of an object."  Duh.  I don't know if there is any easy way to look at the exception to see if it is a validation error versus a system sql failure, but that's not the point, it's a stupid strategy.

A suggestion I'm making going forward is to handle system errors and validation errors separately.  I'm not an expert on user interaction design, but I'm pretty sure you're not supposed to be sending raw exception messages to users.  Plus it's just stupid to use exceptions for control logic.  Not to mention it's incredibly moronic to create user messages in stored procedures.  We know we'll need to provide some internationalization eventually.  The idea that I'll have to scour stored procedures to localize the web displays pisses me off.  Add in the fact that we need to support multiple database engines -- and I'm starting to get red-faced so I'll stop now. 

Just a plea to my colleagues, let's please stop abusing stored procedures.  Put business logic and UI code in predictable places and let's start thinking of better ways to do exception management.  If you don't stop putting crap in sprocs, I'm gonna start getting angry and I'm bigger than you are.

 

 


Published Jul 27 2005, 03:25 PM by Jeremy D. Miller
Filed under:

Comments

Darrell said:

>> but I'm pretty sure you're not supposed to be sending raw exception messages to users. <<

Not to mention a security issue.
# July 27, 2005 11:28 AM

Jeffrey Palermo said:

Yeah, Jeremy. You are bigger than a lot of people. A corn-fed Texas boy!
# July 27, 2005 1:10 PM

Harris said:

My thoughts...if you please...
# July 27, 2005 3:23 PM

Colin Kershaw said:

This reminded me of a post Bill Caputo had that covered error management, though it was about simple classes:

http://www.williamcaputo.com/archives/000125.html
# August 4, 2005 1:45 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Jeremy D. Miller

Jeremy began his IT career writing "Shadow IT" applications to automate his engineering documentation, then wandered into software development because it looked like more fun. Jeremy previously worked as a systems architect building mission critical supply chain software for a Fortune 100 company and learned agile development practices as a .Net consultant at ThoughtWorks, one of the pioneers of agile development. Jeremy is the author of the open source StructureMap (http://structuremap.sourceforge.net) tool for Dependency Injection with .Net and the forthcoming StoryTeller (http://storyteller.tigris.org) tool for supercharged FIT testing in .Net. Jeremy's thoughts on just about everything software related can be found on his weblog "The Shade Tree Developer" at http://codebetter.com/blogs/jeremy.miller, part of the popular CodeBetter site. Jeremy is a Microsoft MVP for C#. Check out Devlicio.us!

This Blog

Syndication

News

All opinions expressed here constitute my (Jeremy D. Miller's) personal opinion, and do not necessarily represent the opinion of any other organization or person, including (but not limited to) my fellow employees, my employer, its clients or their agents.

About Me

"Best Of" Compendium

StructureMap (Dependency Injection for .Net)

StoryTeller (Supercharged Fit)

Build your own Cab

TestDriven

MVP