This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logging Embedded within exceptions

 
Dan Burke
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I am adding logging into data object. I have the URLyBird asssignment.

What i'm doing is logging when exceptions before i throw them or once they've been caught. My logging messages and exceptions messages parallel eachother. So the code is a bit verbose.

log.info("same message as below");
throw new exceptions("same message as above");

My proposed solutions is to add a new constructor to each exception class. The contrustor will take the message and a reference to my logger object.

That way i've delegated / chained the logging into the exception objects.

Can anyone see a problem with this? I'm concerned about bad practise or breaking the specs.

Cheers

Dan
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are tieing dependency on you exception to your logger which seems bit weird.
[ February 27, 2006: Message edited by: Ed Tse ]
 
Dan Burke
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Admintantly it is. It also makes my code less cohesive and increases coupling. Earlier i decided against doing it in the first place. Code beuatification has no place in good design.
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May I ask why you would log when an exception is throw? Usually, the catcher logs the exception and the exeception has stack trace of where it get thrown from.
 
Dan Burke
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was a conviencience issue really. Logging the exception when it is constructed is the same as saying catch the exception when its thrown and then log it. My original thought was to combine the logic to abstract logging from my classes. That way your logging code is minimalised substantially - especially with the expection chaning that this assignment requires.

The big problem with this approach is that it does break some principles of OO which i mention above..and for this assignment i wouldnt risk doing stuff like this.

Bit of a dud post really - i would have deleted it if i could have.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic