Is this good C# style?

Posted by burnt1ce on Stack Overflow See other posts from Stack Overflow or by burnt1ce
Published on 2009-08-13T20:00:58Z Indexed on 2010/04/04 15:53 UTC
Read the original article Hit count: 517

Filed under:
|
|

Consider the following method signature:

public static bool TryGetPolls(out List<Poll> polls, out string errorMessage)

This method performs the following:

  • accesses the database to generate a list of Poll objects.
  • returns true if it was success and errorMessage will be an empty string
  • returns false if it was not successful and errorMessage will contain an exception message.

Is this good style?

Update: Lets say i do use the following method signature:

public static List<Poll> GetPolls()

and in that method, it doesn't catch any exceptions (so i depend the caller to catch exceptions). How do i dispose and close all the objects that is in the scope of that method? As soon as an exception is thrown, the code that closes and disposes objects in the method is no longer reachable.

© Stack Overflow or respective owner

Related posts about coding-style

Related posts about c#