This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Exception Catch block- Email trigger!

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

While working on the older version of code I see that everywhere in the catch block there is an email getting triggered to the admin.

Like:

try{

}catch(Exception e){
logger.debug("Debug message");
mail.send(, , e.getMessage);
}

I feel this unnecessary, however I want to be sure and would like to get your opinions.

Thanks,
Resh
 
Marshal
Posts: 26912
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You've posted three lines of code with no explanation at all. It's completely impossible for anybody else to tell whether they are necessary or not. It would take a lot more explanation from you before anybody else could make a reasonable judgement about that code.

Remember that "necessary" isn't something managed by the Java compiler. It's a business decision made by the users of the software and the designers of the software. So your question is about that business decision.
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We really cannot discuss or ponder over the Business decisions. At times they are useful and at times not.
 
resh singh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks All for replying back.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

resh singh wrote:Hi,

While working on the older version of code I see that everywhere in the catch block there is an email getting triggered to the admin.

Like:

try{

}catch(Exception e){
logger.debug("Debug message");
mail.send(, , e.getMessage);
}

I feel this unnecessary, however I want to be sure and would like to get your opinions.

Thanks,
Resh



It is a business decission but you have asked for an opinion so ill give my opinion.

I think the idea of directly call to a send mail on each exception is a bad idea, particularly if its being done to send error emails to the admin. I think it would be better to log the error properly and if emails where required set up an SMTPAppender in my log4j to capture and send the messages.

I would probably end up with something looks like this.


 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

resh singh wrote:While working on the older version of code I see that everywhere in the catch block there is an email getting triggered to the admin.


I must admit that I once made a system that did something similar. It was a bad idea. The administrator would get thousands, or even tens of thousands of e-mails from the system because there was some small problem that happened on each message that the system was processing. The amount of mail quickly became unmanageable. Ofcourse, not every system is the same, so maybe the circumstances in your system are different.

Most logging systems have different log levels (for example FATAL, ERROR, INFO, DEBUG, TRACE). When designing and implementing your system, it's a good idea to think about how you're going to use those levels. For example, log exceptions with the ERROR level, major entry points with INFO, information that might be useful for the developers with DEBUG etc.

While testing, you can set the log level to DEBUG, so that everything that's interesting for developers is written in the log file. For production, set it to INFO or to ERROR, so that you don't get too much in the log file. Logging also slows down the program, so you probably don't want to log everything in production.

There are tools that you can use to analyze log files and for example filter out all the ERROR messages. In my opinion it is better to use such a tool than to send e-mail to the administrator directly from the application itself - that way you separate the monitoring functionality from the application itself. If you really want the e-mail, you could let the log analyzer tool send the e-mail, instead of the application itself.
 
resh singh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for your responses, I really appreciate it.

That's what I was looking for, I wanted to be sure whats a good practice.

It make more sense to use some log analyzer (specifically on production).

Thank You,
Resh
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic