Nice error messages who handles? UI OR Business Objects?

Nice error messages who handles? UI OR Business Objects?

Old forum URL: forums.lhotka.net/forums/t/3149.aspx


dantruj posted on Friday, July 06, 2007

I would like to know what layer should handle the nice error messages to show to the user?  For example, if a business method in the csla throws an error message (techincal error) and I do not want the UI to display this in an error message box to the user, then what would I do?

1)  Would I rethrow the business error with a nice error from within the business layer?

Or

2) Have the UI log the technical error, then display a messagebox with the nice error in there?

 

 

ajj3085 replied on Friday, July 06, 2007

That sounds like it belongs in the UI layer, so option 2 sounds best.

david.wendelken replied on Monday, July 09, 2007

dantruj:

I would like to know what layer should handle the nice error messages to show to the user?  For example, if a business method in the csla throws an error message (techincal error) and I do not want the UI to display this in an error message box to the user, then what would I do?

1)  Would I rethrow the business error with a nice error from within the business layer?

Or

2) Have the UI log the technical error, then display a messagebox with the nice error in there?

I would reframe your question like this:

    1. What layer is responsible for knowing that this particular error has occurred?
    2. What layer is responsible for providing the information necessary to produce a user-understandable error message?
    3. What layer is responsible for taking the information necessary to produce a user-understandable error message and then turning it into that message.
    4. What layer is responsible for displaying that message to the user in a manner appropriate to the context in which it happens?
    5. What layer is responsible for logging the error in a data store?

Sample answers (and why):

1) What layer is responsible for knowing that this particular error has occurred?

Often the business object layer, but it could be the database layer or the ui layer.  You might not want it to be the database or ui layer, but those layers will generate errors upon occasion regardless of our wishes to the contrary.

So, the answer is: The layer the error is created in is responsible for knowing it happened.

2) What layer is responsible for providing the information necessary to produce a user-understandable error message?

In general, the best place for me is where the error occurred.  That's where the necessary information is available, every place else either has to have it passed in or reconstruct it after the fact.

3) What layer is responsible for taking the information necessary to produce a user-understandable error message and then turning it into that message.

Given that errors can occur in the UI, the UI has to have this capability (even if it just asks another layer to do the work). 

Given that programmers need good error messages as much (or more!) than users, I would do the translation as close to the source of the error as possible.  Makes testing and debugging much easier, although having equivalent translation capability in each layer means a bit more infrastructure setup.

4) What layer is responsible for displaying that message to the user in a manner appropriate to the context in which it happens?

That's the UI.

5) What layer is responsible for logging the error in a data store?

Again, I prefer to do this as close to where the error happens as possible, otherwise some won't get logged and you won't know it (except for the existence of pernicious, hard-to-kill bugs).

 

Hope that helps!

dantruj replied on Tuesday, July 10, 2007

Yes it helps tremendously, thank you.

Copyright (c) Marimer LLC