Context: We have a page which is composed of multiple sections.
Consider for e.g: A product page with Product details, prices, images & offers.
All the sections are shown one after the other in the same order in which they are mentioned.

Our pseudo code to fetch all this data is as shown below:

public Page GetPageDetails()
    pageDto.Details = GetDetails();
    pageDto.Prices = GetPrices();
    pageDto.Images = GetImages();
    pageDto.Offers = GetOffers();

    private Details GetDetails()
        var details = GetDetailsFromDb();
        //Perform some manipulations on "details" object
        return details;

    private Details GetPrices()
        var prices = GetPricesFromDb();
        //Perform some manipulations on "prices" object
        return prices;

    and so on for other types...

    return pageDto;

Even though we have handled various types of errors possible while doing manipulations (null checks, index checks, etc...) we can't afford any type of exception here because if an exception occurs in lets say prices manipulation, it breaks entire page and results in direct monetary loss.

Ideally we would want that if an exception occurs in any section, only that section is not shown and page keeps functioning as usual.

What would be the right way to achieve our goal?

One of the suggestion by the team was to wrap every private function like GetDetails/GetPrices in try-catch and return null in case of error.

  • Is there any reason why you think the team's suggestion would not be right? Commented Aug 10, 2020 at 9:59
  • This is the only opinion we have right now and we feel there might be better ways to resolve this. Also, this seems like a problem which must have been faced by others.
    – vicky99
    Commented Aug 10, 2020 at 10:25
  • Do you expect any specific exceptions to happen?
    – max630
    Commented Aug 10, 2020 at 11:23
  • @max630 - No. We are not expecting any specific exception. If we know an exception can occur, we would handle it beforehand with proper checks but as explained we cannot risk failure. Any unhandled exception will be expensive to the company. Additional point - We do have review processes and tools like "Sonar" setup with us to catch issues as early as possible.
    – vicky99
    Commented Aug 10, 2020 at 12:26
  • 1
    As your team suggest you can handle exception for each private function.and check basic exception that arise at a time of db operation.and return null if exception occur in any section.
    – AjayGohil
    Commented Aug 10, 2020 at 16:23

1 Answer 1


The suggestion of the team to catch the unexpected exceptions in the private functions that each retrieve a section of the page is a very good way to ensure that a failure in one section does not affect the displaying of the other sections.

As you are trying to hide these failures from the end-user and as they should be rare, be sure to add sufficient logging to the exception handler that you can reconstruct what happened without having to search for that once-in-a-lifetime set of conditions that triggered the failure.

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.