473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Error Handling/Display in an n-tier Design?

I was wondering if anyone can point me to some articles or practices they
use for dealing with errors in their applications; particularly in an n-tier
design. I am trying to find one way to conveniently handle both soft and
hard errors, primarily for display to the end user.

One method I have considered is rethrowing exceptions. With this approach, I
would throw a plain old ApplicationException, with the Message property as
the polite message for the user, and the InnerException as the exception
that actually occurred(although this might not be necessary, since the
actual error would be immediately logged for debugging purposes). The major
drawbacks I have seen with this, is that it appears to be a frowned upon due
to extra resource usage(does anyone have any hard figures?), and that
exceptions should be used for exceptional happenings(meaning that failing a
security check shouldn't mean an exception is thrown). One other major issue
is that it is difficult(if not impossible) to use in a scenario where some
steps in a process can fail and should be reported, but they do not mean
that the whole process failed.

The other method I have considered is maintaing an error collection that is
populated with errors when they occur, and passed around the business layer,
and data layer. This seems like the way to solve the issue of multiple steps
failing, and not adding the additional resource consumption by throwing
errors. The major issue it does bring up is that after every call to the BL,
we must check the error collection for errors, and output them if need be,
and stop further processing if necessary. Although this could be wrapped up
with a call to a static function somewhere after each call to the BL, it
still seems like it would be a maintenance nightmare in the future.

Any thoughts, ideas, current practices, or articles would be most
appreciated.

Thanks,
Steve
Nov 15 '05 #1
3 4758
Hi Steve,

I don't have any article I could point you to. But overall, your strategies
seem right. My comments are in-line:

"Steve - DND" <steve!@!digitalnothing.com> a écrit dans le message de
news:%2****************@TK2MSFTNGP11.phx.gbl...
I was wondering if anyone can point me to some articles or practices they
use for dealing with errors in their applications; particularly in an n-tier design. I am trying to find one way to conveniently handle both soft and
hard errors, primarily for display to the end user.

One method I have considered is rethrowing exceptions. With this approach, I would throw a plain old ApplicationException, with the Message property as
the polite message for the user, and the InnerException as the exception
that actually occurred(although this might not be necessary, since the
actual error would be immediately logged for debugging purposes).
This works really well. The user should only see the message of the top
level exception (maybe with a button to see the details), and you should log
everything (all messages + traceback) for debugging purposes.
The major
drawbacks I have seen with this, is that it appears to be a frowned upon due to extra resource usage(does anyone have any hard figures?), and that
exceptions should be used for exceptional happenings(meaning that failing a security check shouldn't mean an exception is thrown).
The extra resource usage is not a problem if you use it only for exceptional
happenings. And you have to, otherwise your exception logs will explode.

My recommendation is to use exceptions only for exceptional happening, i.e.
events that are due to unexpected I/O failures, bugs, installation problems
(file missing), etc. Everything else (for example, validating user input)
should be done through function calls, if/then/else tests, etc., not through
exception handling.

The case of security checks is interesting. My approach is that the BL layer
should throw exceptions when a security check fails but it should also
expose methods to test if an operation is allowed or not (security queries).
The UI layer should use these security queries to configure the UI and
inform the user when an operation is not allowed. If the UI layer is
correctly implemented, the BL layer should not throw any exception. In this
approach, exceptions are only used for exceptional happenings (security hole
in the UI layer).

Also this general approach (using exceptions only for exceptional
happenings) is in line with the "contracting" metaphor and the "disciplined
exception" methodology that B Meyer describes in Object-Oriented Software
Construction (Prentice Hall)
One other major issue
is that it is difficult(if not impossible) to use in a scenario where some
steps in a process can fail and should be reported, but they do not mean
that the whole process failed.
Yes, this is an issue. In this case, every process that is allowed to fail
should catch all exceptions, log them, and return some kind of error/warning
object to its caller. The higher level code should display these
errors/warnings to the user.

The other method I have considered is maintaing an error collection that is populated with errors when they occur, and passed around the business layer, and data layer. This seems like the way to solve the issue of multiple steps failing, and not adding the additional resource consumption by throwing
errors. The major issue it does bring up is that after every call to the BL, we must check the error collection for errors, and output them if need be,
and stop further processing if necessary. Although this could be wrapped up with a call to a static function somewhere after each call to the BL, it
still seems like it would be a maintenance nightmare in the future.
Well, this is a very good way to handle the situation that you described
before (process that fails without causing the entire process to fail). We
actually use this in conjunction with exceptions. The idea is the following:

* At the low level, we use E.H. to signal abnormal situations.

* At the high level, we have processes that may recover. These processes log
the errors and populate collections of error objects that the top level uses
to inform the user.

This works quite well, but we don't pass an error collection everywhere. As
you say, this would quickly lead to a maintenance nightmare (and also a lot
more code in the first place).

Any thoughts, ideas, current practices, or articles would be most
appreciated.

Thanks,
Steve

Nov 15 '05 #2
> Well, this is a very good way to handle the situation that you described
before (process that fails without causing the entire process to fail). We
actually use this in conjunction with exceptions. The idea is the following:
* At the low level, we use E.H. to signal abnormal situations.

* At the high level, we have processes that may recover. These processes log the errors and populate collections of error objects that the top level uses to inform the user.

This works quite well, but we don't pass an error collection everywhere. As you say, this would quickly lead to a maintenance nightmare (and also a lot more code in the first place).


Thanks for the input. I'm curious though. How exactly does the presentation
layer know that there is something to display in terms of messages? Does it
only check the errors collection at the end of the process(as opposed to
after every step as I had mentioned)?

Thanks,
Steve
Nov 15 '05 #3
> Thanks for the input. I'm curious though. How exactly does the
presentation
layer know that there is something to display in terms of messages? Does it only check the errors collection at the end of the process(as opposed to
after every step as I had mentioned)?


Yes, the UI checks if the collection is empty or not. If not, it displays
the list of errors (our app is a Web app, so the UI cannot intercept errors
in the middle, it can just submit, pray, and see the results).

The BL layer can also test the collection and skip some sub-processes if the
collection is not empty and the BL layer knows that these processes should
only be attempted when all the other sub-processes went ok before (but in
practice, there are very few cases where we can actually do this).

But the general idea is to limit the use of error collections to the few
places where we have steps that may fail without causing everything to fail
(there are usually few of these and they are usually at a rather high level
in the logic) and to use exceptions for all the rest (simpler, easier to
code, and usually more robust, even if it not always very subtle).

Of course, these are just indications on how we solved our problems. Yours
may be slightly different and may need a different cure.

Bruno.

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: WSeeger | last post by:
When creating a new class, is it encouraged to always include error handling routines within your LET and GET procedures? It's seems that most text books never seem to include much about error...
1
by: monika | last post by:
hi... when I try to insert a duplicate record I get the primary key error. which is good. but I want to generate a user friendly error ... telling the user that u have got this error because u r...
3
by: Kim Haines | last post by:
I need help finding where an error is occuring in my code. I use a try-catch block like this in my global.asa: try { //my code } catch (e) { Application('errormsg') = ("An exception...
1
by: Jon LaRosa | last post by:
Hi all - I have a web application and I want to be able to do some basic error handling. For example, here is one error I would like to catch and display in a useful way for the user: ...
3
by: thomasp | last post by:
If I have a Try Catch block that captures an exception in a function located in a module called by a form, in other words burried in the code, and this exception is not one that can be corrected,...
7
by: Garth Wells | last post by:
I'm trying to create a DAL and am wondering what's the proper way to handle errors in this Insert method. public string Insert() { Database db = DatabaseFactory.CreateDatabase(); string...
5
by: csgraham74 | last post by:
Hi guys, Basically i have been developing in dotnet for a couple of years but ive had a few issues in regards to error handling. For example - I have a class that i call passing in a stored...
4
by: John Wright | last post by:
I need some good ideas or references for robust error handling in VB.NET. I am using try catch but find myself using the generic exception handler. I would like to get more precise error handling...
4
by: anisu | last post by:
Hi, I am trying to do error handling during insert in MS Access 2002 (OS: MS XP) The problem is that when a duplicate record is added for the primary key field or a null value included in a...
16
by: john6630 | last post by:
Coming from the .Net world, I am used to the try...catch...finally approach to error handling. And PHP 5 now supports this approach. But I am not clear what happens to unhandled errors/exceptioins?...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.