Any error that could be produced at the page level, either at a grid list or a simple tab page (excluding XML pages, which are dynamically  generated), may result in an unhandled exception that usually stops the loading of the page and renders an "exception page".

In order provide a better user experience, we need to handle any possible errors that my occur during the loading of the page, for example when retrieving data from the DB in order to use them when the page loads.

We have created a new exception type, OneDealerHandledException, which inherits from the Exception class and takes as parameter the desired message that will be presented at the error page in case of a "handled" error.

Where we need to check something, if the check fails, we throw this exception type with the desired message. For example, here we have a check after we try to retrieve the Business Partner entity.

var businessPartnerResult = DimensionPermissionsCheckManager.GetResultWithDimensionsCheck(()
    => BusinessPartnerManager.GetBusinessPartnerEntity(BpCode, true, bpFields));

if (businessPartnerResult.HasError)
{
    throw new OneDealerHandledException(businessPartnerResult.ErrorMessage);
}

Instead of accidentally raising a NullReferenceException by just using the variable BusinessPartner later below in the code, we "throw" an OneDealerHandledException with the message that may reflect what happened.

Basically, this kind of logic needs to applied at each OneDealer page at various points, with the appropriate message each time in order to be as specific as possible.

This exception will be caught at 2 possible places:

  • OneDealerActionInvoker.OnActionExecuted
    • In case of requests from controllers, especially AJAX requests, it is called after them and any unhandled exceptions can be found at the context.Exception property
    • In case of page views, it is called after the page was rendered and after any exceptions that may have occurred. No unhandled exceptions can be found at the context.Exception property
      • However, if an unhandled exception or an exception is thrown at the OnInjectInitializeMethod, the context.Exception property is filled and the Exception Page is setup there instead of the try/catch at the PageViewResult class
  • PageViewResult.ExecuteResultAsync
    • In "Release mode", there is a try/catch that catches any unhandled exceptions thrown during the rendering of the page. An ExceptionPage is created which will contain the stacktrace of the exception and any BusinessErrors set from managers

The ExceptionPage class was enhanced with 2 new properties:

  • Message
    • Defined when throwing the exception
  • IsHandledException
    • If the exception type is OneDealerHandledException, this property is true
    • Right now it is used to differentiate wording at the page


0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.