Logging

  • Thread starter Thread starter Einar Høst
  • Start date Start date
E

Einar Høst

Hi,

I'm doing some logging using the Trace-functionality in .NET, which works
pretty well for me. However, I'm wondering how I should go about logging
data about exceptions that occur. Lately, I've started writing code like:

try
{
...
}
catch (MyException ex)
{
HandleMyException(ex);
}

where HandleMyException looks something like:

void HandleMyException(MyException ex)
{
// Do any clean-up.

// Write to log.

// Swallow or rethrow, depending on the nature of MyException.
}

Similarly, I've started writing code like this:

if (someCondition)
{
ThrowMyException();
}

where ThrowMyException may look something like:

void ThrowMyException()
{
// Write to log.

throw new MyException();
}

Is this good practise? Bad practise? Your wise thoughts are well appreciated
:-)

Regards,
Einar
 
Hi

Actually writing your own exception class is very useful when you are using layers; For example you can define an exception class for data access then handle it in bussiness layer acording to bussiness rules
also for presentation layer you can create an exception class with userfriendly messages and apply some common user interface behavoir for handling exceptions.

Regards,

Dincer Uyav
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top