Greg Beech's Website

Browse by Tags

  • Disposing and finalizing partially constructed objects

    On MSDN forums there was a question about whether class constructors should be permitted to do a lot of work or not : I have a dilemma and a dispute with some colleagues: should the constructor of a C# class do a lot or the minimum and latter in a method call put a lot of logic? I am coming from a C++ background and there it is better to do just simple data initialization in the constructor, throwing...
  • Pragmatic exception management, Part 2

    In the first entry in this series I looked at what medium-to-large companies and developers want from an exception management framework, and derived some requirements from this. To recap, these are the high level requirements, which you'll note that no current framework is even close to meeting. Publish all exceptions to the Event Log No configuration files required Auto-generate boiler plate exception...
  • Pragmatic exception management, Part 1

    At Netstore we've spent quite some time over the last six months implementing a custom diagnostics and exception management framework. You might think this is a sign of the Not Invented Here syndrome, which I guess it is, but believe me we wouldn't have spent the equivalent of a fortune in consulting days building it unless we thought there was a good reason. The trouble is, after evaluating...
  • Why do we have different types of exception?

    The short answer is to allow them to be handled differently in a programmatic manner. You've probably done it hundreds if not thousands of times - creating a try/catch block and catching an exception based on its type to handle it in a particular way. So the headline question in itself isn't particularly interesting; however the answer's simple premise leads us to a couple of the fundamentals...
  • Often the obvious solution is the right one

    The rule "don't use exceptions for flow control" is one that should rarely be broken, partly because it makes the code much less readable, and partly because it will seriously compromise the performance of a solution. To give you an idea of the sort of impact exceptions can have, one website I tuned threw an exception if an item wasn't contained in its custom cache, which was often;...
  • Why doesn't C# have exception filters?

    Recently I was working on a simple message receiver from MSMQ queues. The MessageQueue.Peek() method is pretty poorly designed as instead of returning a Boolean or null when there is no message on the queue, it throws a MessageQueueException with the MessageQueueErrorCode set to IOTimeout. Why is this bad? Firstly exceptions should only be thrown on unexpected circumstances and a queue being empty...
    Filed under: ,
Copyright (C) Greg Beech. All rights reserved.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems