473,761 Members | 10,057 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 4781
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
3272
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
3857
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
52044
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
2955
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
1199
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
2364
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
1736
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
1970
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
9491
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
5056
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
9521
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
9333
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,...
1
9900
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
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
8768
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...
1
7324
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3863
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
3
3442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2733
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.