473,414 Members | 1,707 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,414 software developers and data experts.

Good error handling design

GS
Any points of what would be the good error handling design for application?
User error handling in Application_OnError and throw() new errors on conditions through the code?
I'd like utlimiately to consolidate all error_handling in one method which I'll be able to easily modify to write to event log or text file etc instead of error hanlding scattered through the code.

Thanks,
GS
Jan 8 '06 #1
1 1853
Hi GS,

Error handling may have to be scattered in the code - this depends upon who
could handle the exception.

A few pointers which might help:
1. Can the exception be mitigated locally (within that method)?
If YES, then catch that specific exception (strongly typed), solve the error
(or do something about it). If the upper layers might have something to do
about this, then rethrow the exception. If you are not going to rethrow, and
this exception might be interesting to the admin, log it locally.

If NOT, let the exception propagate - maybe the upper layers would be able
to handle it. You needn't even have a try-catch block in this case. A catch
block with nothing but a throw statement for that same exception is the same
as not having a catch block.

2. Are you using Disposable types in the try block?
If YES, then add a finally block and dispose the object in it after making
sure it is not null. You would make use of try-finally blocks with no catch
blocks for this; this is good error handling design.

3. Add an unhandled exception handler.
Note that depending upon the application type (ASP.NET, Windows Service
etc.) the way you handle unhandled exceptions would differ. Add your logging
code here. Make sure that the logging code does not take a very long time -
the end use is waiting! In fact, some applications make use of asynchronous
error logging so that performance is not affected.

4. Do NOT catch base exceptions like Exception.
Ideally exceptions should not be hidden by having a catch all block like
'catch(Exception ex)'. This would hide possible flaws in your application -
let them propagate so that you could handle it in a properr way before the
app ships.

For more info on error handling in ASP.NET, check out:
http://www.codeproject.com/aspnet/er...lingaspnet.asp

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.rakeshrajan.com/
"GS" wrote:
Any points of what would be the good error handling design for application?
User error handling in Application_OnError and throw() new errors on conditions through the code?
I'd like utlimiately to consolidate all error_handling in one method which I'll be able to easily modify to write to event log or text file etc instead of error hanlding scattered through the code.

Thanks,
GS

Jan 9 '06 #2

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

Similar topics

12
by: Christian Christmann | last post by:
Hi, assert and error handling can be used for similar purposes. When should one use assert instead of try/catch and in which cases the error handling is preferable? I've read somewhere that...
16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
1
by: michaeltorus | last post by:
Hi I'm currently designing a new web application in .Net. I've pretty covered everything, apart from error handling. There seems to be a few different way to do this, but something I've read...
0
by: chopsnsauce | last post by:
Hello, I've just written, my first .NET Windows application and I've noticed that when running my App in the design time enviroment the error handling works like this: Say I've gat a method...
3
by: Agnes | last post by:
My client hold its MS SQL server in hkbranch, Both china and hong kong office can run the vb.net application very well via VPN. Now, they want to reduce cost and move the MS SQL server to china 's...
1
by: GS | last post by:
Hello, I'd like to centralize error handling in my ASP.NET project. How exactly I design classes so all expections will be handled by single error handler for the whole project? Any simple code...
35
by: jeffc226 | last post by:
I'm interested in an idiom for handling errors in functions without using traditional nested ifs, because I think that can be very awkward and difficult to maintain, when the number of error checks...
94
by: Chad | last post by:
On to top of page 163 in the book "The C Programming Langauge" by K & R, they have the following: char *strdup(char *s) { char *p; p=(char *)malloc(strlen(s)+1); if( p != NULL) strcpy(p,s):...
9
by: arnuld | last post by:
Can anyone point me to some online/offline document on error handling in C ? I am doing some Socket Programming in C and feeling a lots of difficult in error handling :( Also some time ago...
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
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...
0
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...

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.