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.