Tech Off Post

Single Post Permalink

View Thread: Error Handling, use exceptions?
  • User profile image


    A question that I have never really found a good answer for is what is the best way to inidcate common errors in a method?

    The options would be:

    - Indicate using the return object. The problem here is returning false or null doesn't say much about what caused the error,

    - Indicate using a return type and set an error property. This is the equivalent of the Win32 GetLastError call. Problem with this is it needs broad acceptance and since it's not done this way in the .Net base library would just cause confusion,

    - Throw exceptions on any error conditions encountered. Problem with this is it's supposed to be bad practice.

    The throw exceptions approach seems to me the most elegant and flexible. Obviously it brings in a performance hit but in the context of managed code is it a significant one?

    The .Net base libraries seem to throw exceptions for easily detected conditions. Is the consesnus error handling approach in the .Net libraries to throw exceptions?