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.
Question:
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.