views:

232

answers:

4

I was given a task of write the coding guidelines for my team, and it was going great until my manager asked me to write an explanation of Why Error Handling is Important.

I know it instinctively, but how do I put this down into words?

I tried to google it fisrt but came up empty, so I ask my fellow coding whiz, for an answer.

+1  A: 

Why Error Handling is Important.

Because of what can happen if you don't.

If you're capable of writing coding guidelines, you should be able to handle this, surely?

Paul
Perhaps, Paul. But sometimes, even the best of us have doubts about how to say something. And StackOverflow is always the BEST place to ask coding related quetions.
Paulo Santos
Yeah, I'm ill so I'm grumpy today, but sometimes I feel questioners could put a little effort in first...
Paul
A: 

Error handling is important because it makes it easier for the end users of your code to use it correctly. Another important issue is that it makes your code easier to mantain. Error handling makes it easier to embed input specifications into the code, so you don't have to look up the design when you write and later mantain the code.

Egil
+1  A: 

First I would ask is it important?

I've seen (ugly) code where some errors were ignored (eg null reference)

So what type of errors are important to handle?

There is a big difference between System.IO.FileNotFoundException, System.Data.SqlClient.SqlException and System.ApplicationException

Good luck!

Christian Payne
+3  A: 

IMHO ... most programs are very large, very complex and written by multiple people. This combination of factors almost always leads to some kind of software bug. It's not that programmers are malicious, stupid or lazy ... it's just that in the rush to meet a deadline we often don't forsee every possible thing that a user can do to our programs and something is bound to happen.

In this respect error handling serves two purposes.

  • First, it lets the user know, in a relatively friendly manner, that something has gone wrong and that they should contact the technical support department or that someone from tech support has been notified. As we all know there's a HUGE difference between receiving a rather nasty, tech riddled notice that says something like "Object not set to reference of an object" etc. ... and receiving a nice popup type window that says "There has been an issue. Please contact the helpdesk".

  • Second it allows the programmer to put in some niceties to aid in the debugging of issues. For instance ... in my code, I typically write a custom error handler that takes in a number of parameters and spits back a nice, formatted message that can either be emailed to the helpdesk, stashed in an event log, written to a log file etc.. The error message will contain as much info as I can cram in there to help me figure out what happened, stack traces, function parameters, database calls ... you name it. I like verbose error messages to help me figure out what actually happened. The user never has to see any of it, they get the nice, friendly message above, letting them know that someone can figure out what's going on.

Hope this helps

Scott Vercuski

Scott Vercuski