473,399 Members | 3,038 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,399 software developers and data experts.

Exception Handling Question: Event Logging

ETL
Hi,
I think this question has an easy answer but I can't seem to find
anything online that lists best practices for my problem.

I have a C# app that uses an exception handling tree similar to the
following.

Try
{
blah blah blah....
}
catch(UnauthorizedAccessException noAuth){}
catch(IndexOutOfRangeException){}
catch(Exception Ex){}
finally{}

I want to log an event on my server if any of the following exceptions
are thrown. My server logging methog looks like this:

LoggingManager.LogServerEvent(Exception.Message.To String());

I can add this method to each catch clause and it alogs the event fine.
I'd like to optimize my code so that this logging method is only in one
place. It seems silly to put it in all the catch clauses. Basically, if
ANY exceptions was raised, log it.

Any suggestions?

Thanks

Eric

Nov 17 '05 #1
2 1494
I think you'll have to catch it in each catch block. unless there's a
way to trigger an event on any exception, then use that event to log the
exception, you'll have to put it in each place.

that's my admittedly limited experience, anyway.

--
jeremiah();

ETL wrote:
Hi,
I think this question has an easy answer but I can't seem to find
anything online that lists best practices for my problem.

I have a C# app that uses an exception handling tree similar to the
following.

Try
{
blah blah blah....
}
catch(UnauthorizedAccessException noAuth){}
catch(IndexOutOfRangeException){}
catch(Exception Ex){}
finally{}

I want to log an event on my server if any of the following exceptions
are thrown. My server logging methog looks like this:

LoggingManager.LogServerEvent(Exception.Message.To String());

I can add this method to each catch clause and it alogs the event fine.
I'd like to optimize my code so that this logging method is only in one
place. It seems silly to put it in all the catch clauses. Basically, if
ANY exceptions was raised, log it.

Any suggestions?

Thanks

Eric

Nov 17 '05 #2
Hi Eric,

You did not give all the details of the blah blah part of your code,
now based on the limited information :
- why do you have to catch three types of exceptions ? can you
refactor your blah blah part of the code ? it seems to me that this
method has different roles, granting access, getting elements from an
array, etc
- it is sufficient to catch Exception and log the Message, you will
have the same functionality as you have know (Exception is the base of
the other exceptions)
- check the exception handling on
http://www.microsoft.com/downloads/d...displaylang=en

success,
Bart

http://www.xenopz.com

Nov 17 '05 #3

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

Similar topics

6
by: Kevin Jackson | last post by:
Let's say we log exceptions to the windows application event log using the Exception Management Application Block. Is there a pattern that can be used so the exception is logged only once and not...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
4
by: sm | last post by:
Hi, I have a couple of questions with regards to handling errors and exceptions. 1. If I use On Error goto Errhandler ... Errhandler:
1
by: David Herbst | last post by:
Enterprise Library Jan 2006 with Visual Studio 2005 on Windows 2000 Server sp4. My custom exception formatter fails with a "Unable to handle exception: 'LoggingExceptionHandler'." exception. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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,...
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
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,...
0
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...

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.