Today, I’ve been reviewing some piece of source code,  and found way too interesting exception handling approach.

In following code snippet we are trying to wrap existing exception with new one having more descriptive message and saving the stack trace of the original exeption. The way how it is done is just amazing:

        private void OnProcessingException(Exception exception)
        {
            if (ExceptionOccured != null)
            {
                try
                {
                    throw new Exception(string.Format(“Very descriptive message here.” + “{1}StackTrace of InnerException: {0} {1}”, exception.StackTrace, Environment.NewLine), exception);
                }
                catch (Exception outerException)
                {
                    ExceptionOccured(this, new ProcessorExceptionEventArgs(outerException));
                }
            }
        }

I’m not trying to blame someone. But sometimes people see so much more complicated and sophisticated solutions to problems that could be solved with one-two lines, that it makes me think, what we also do such things but on another – higher level.

Developer who wrote this code is trainee, so doesn’t mean low quality of our code, simple he needs more experience. My point is that we are also trainee, but on another level, and we might not see simple solutions as well.

So who will write me one-or-few lines of code that can do the same? Please do not hesitate :)