I have a CRM system that has Notes, Payments, DairyEvents and anything else that needs to be bolt on over time.

I created an ITimeline interface that has a datetime and message method and implemented them on those models.

This is the simplest form of code I have started with:

public static List<Interfaces.ITimeline> GetAll(long personID)
    List<Interfaces.ITimeline> timelineEvents = new List<Interfaces.ITimeline>();

    //add more to the list as the system grows

    return timelineEvents;

That is fine, as long as one of the controllers doesn't throw and error, then the whole Interface collapses. I had something similar happen on a another project, production environment, where a single provider went haywire due a bug on their system, amongst several other providers that were being interfaced with and worked fine. It wouldn't be so bad if it didn't crash all 600+ sites, just because of that mistake somebody else made.

I don't want to do try catches around every single addrange - I think that is just cluttering. Also, with integration like that, you build things to work, but exceptions happens here and there.

What is a proper way of taking data from various sources, controllers or integration, adding them to a collection of items for the interface? That way, if something fails in the middle, it won't bring down the entire page, or even worse, the whole framework.


1 Answer 1


The error should be caught where it occurs, namely in the controller. If possible try to implement something like this

TimelineEventCollection personTimelineEvents; // Change to the appropriate collection type.
if (Controllers.FollowUp.TryGetAll(personID, out personTimelineEvents)) {

The advantage of this approach is that the error does not get swallowed up silently by some try-catch-statement. You get a Boolean return value from TryGetAll telling you if all went right. At the same time the basic error handling happens in a low level method and not in your list filling routine.

If you cannot alter the Controllers.FollowUp class, you can still write an extension method giving you the same functionality.

  • \$\begingroup\$ That is SOLID advice! Defiantly a great approach, I use TryGet almost daily and never thought of doing that on my own code! Thanks +1 \$\endgroup\$
    – Piotr Kula
    Commented Apr 15, 2014 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.