473,847 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ApplicationExce ption, with the Message property as
the polite message for the user, and the InnerException as the exception
that actually occurred(althou gh 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(mean ing 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 4785
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!@!digita lnothing.com> a écrit dans le message de
news:%2******** ********@TK2MSF TNGP11.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 ApplicationExce ption, with the Message property as
the polite message for the user, and the InnerException as the exception
that actually occurred(althou gh 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(mean ing 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 "contractin g" metaphor and the "discipline d
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
3277
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 handling within classes. Just hoping to hear some programmer's thoughts on error handling.
1
3863
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 trying to insert a duplicate record. i can simply do so by using "on error resume next".... this is what I do: "on error resume next server.transfer("error.asp")" the problem is it simply takes me to a page where I display an error has
3
52048
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 occurred in the script. Error name: " + e.name
1
2961
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: ----------------- Microsoft OLE DB Provider for ODBC Drivers error '80040e14' UPDATE statement
3
1202
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, how do I exit the program? I have a nice messagebox pop up and tell the user that there has been an error and the program needs to be shut down, but I don't know how to code the shut down. Thanks, Thomas
7
2370
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 sqlCommand = "pr_testx"; DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
5
1739
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 procedure and connection string as a path. My method returns a dataset. In my SP i have an output parameter which tells me whether the SP select is successful or not. If i get a error code passed back then i throw an exception this then returns...
4
1975
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 so I can take appropriate action and display user friendly error messages back to the client. The problem I am getting is determining which error types can be thrown for each function/sub and handling them. Is there a way to determine all the...
4
9495
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 unique filed, an error appears: "Microsoft Access cannot append all the records in the append query!" What I want is to suppress this message and display my own message, but both this message and mine one comes while I do the error handling. ...
16
5069
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? Do I define a default error handler as well as do my try/catch? Can I mix error handling with the exceptions? Is one approach better than the other? TIA John
0
9886
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9730
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10983
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10338
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9482
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7056
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4119
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3164
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.