email from catch or exception

Discussion in 'Java' started by RVic, Dec 11, 2013.

  1. RVic

    RVic Guest

    Is anyone aware of a public domain package that can email you on an error, include the stack trace or log, whenever an exception occurs? Thank you, RVic
    RVic, Dec 11, 2013
    #1
    1. Advertising

  2. On 12/11/2013 2:55 PM, RVic wrote:
    > Is anyone aware of a public domain package that can email you on an
    > error, include the stack trace or log, whenever an exception occurs?
    > Thank you, RVic
    >


    Easy enough to write something. Look at Java Mail,
    https://java.net/projects/javamail/pages/Home.

    --

    Knute Johnson
    Knute Johnson, Dec 11, 2013
    #2
    1. Advertising

  3. RVic

    Eric Sosman Guest

    On 12/11/2013 5:55 PM, RVic wrote:
    > Is anyone aware of a public domain package that can email you on an error, include the stack trace or log, whenever an exception occurs? Thank you, RVic


    I think you'd have to modify the JVM itself to do this. But
    you wouldn't want to: If you got an E-mail for every exception
    thrown, you'd drown in E-mail.

    Presumably, what you really want is E-mail about "important"
    exceptions, and the hard part is clarifying what "important" means.
    Could you describe your use case in more detail?

    --
    Eric Sosman
    d
    Eric Sosman, Dec 11, 2013
    #3
  4. RVic

    RVic Guest

    On Wednesday, December 11, 2013 5:55:34 PM UTC-5, RVic wrote:
    > Is anyone aware of a public domain package that can email you on an error, include the stack trace or log, whenever an exception occurs? Thank you, RVic


    Looking to send an email on exceptions that are caught, and a general one for those that are uncaught.

    I dont mind if there are a ton of emails!
    RVic, Dec 11, 2013
    #4
  5. RVic

    RVic Guest

    On Wednesday, December 11, 2013 5:55:34 PM UTC-5, RVic wrote:
    > Is anyone aware of a public domain package that can email you on an error, include the stack trace or log, whenever an exception occurs? Thank you, RVic


    I thought maybe there was a commons package to do all this relatively simply.
    RVic, Dec 11, 2013
    #5
  6. RVic

    Arne Vajhøj Guest

    On 12/11/2013 5:55 PM, RVic wrote:
    > Is anyone aware of a public domain package that can email you on an
    > error, include the stack trace or log, whenever an exception occurs?


    Put a log4j logging statement in the catch clause and configure
    log4j to use an SMTPAppender.

    Arne
    Arne Vajhøj, Dec 12, 2013
    #6
  7. RVic

    Arne Vajhøj Guest

    On 12/11/2013 6:13 PM, Eric Sosman wrote:
    > On 12/11/2013 5:55 PM, RVic wrote:
    >> Is anyone aware of a public domain package that can email you on an
    >> error, include the stack trace or log, whenever an exception occurs?

    >
    > I think you'd have to modify the JVM itself to do this. But
    > you wouldn't want to: If you got an E-mail for every exception
    > thrown, you'd drown in E-mail.
    >
    > Presumably, what you really want is E-mail about "important"
    > exceptions, and the hard part is clarifying what "important" means.
    > Could you describe your use case in more detail?


    In theory exceptions should be for exceptional cases meaning
    no drowning in emails.

    I have seen many apps where your concerns are valid though.

    Arne
    Arne Vajhøj, Dec 12, 2013
    #7
  8. RVic

    RVic Guest

    Perfect Arne. I need to find an example of such an appender, but thats exactly what I am looking for. THank you.
    RVic, Dec 12, 2013
    #8
  9. RVic

    Arne Vajhøj Guest

    On 12/11/2013 7:28 PM, RVic wrote:
    > Perfect Arne. I need to find an example of such an appender, but thats exactly what I am looking for. THank you.


    log4j comes with the SMTPAppender.

    Arne
    Arne Vajhøj, Dec 12, 2013
    #9
  10. RVic

    Arne Vajhøj Guest

    On 12/11/2013 7:50 PM, Arne Vajhøj wrote:
    > On 12/11/2013 7:28 PM, RVic wrote:
    >> Perfect Arne. I need to find an example of such an appender, but thats
    >> exactly what I am looking for. THank you.

    >
    > log4j comes with the SMTPAppender.


    You only need to configure log4j to use it.

    Arne
    Arne Vajhøj, Dec 12, 2013
    #10
  11. RVic

    Eric Sosman Guest

    On 12/11/2013 6:23 PM, RVic wrote:
    > On Wednesday, December 11, 2013 5:55:34 PM UTC-5, RVic wrote:
    >> Is anyone aware of a public domain package that can email you on an error, include the stack trace or log, whenever an exception occurs? Thank you, RVic

    >
    > Looking to send an email on exceptions that are caught, and a general one for those that are uncaught.
    >
    > I dont mind if there are a ton of emails!


    I honestly do not know how many exceptions are thrown each
    second in a "typical" Java program. As I said in another post
    I think you'd have to modify the JVM to find out -- or maybe
    you could use something in java.lang.instrument, a package I've
    never had occasion to unwrap. Perhaps you should loosen that
    ribbon a bit before writing "I want ALL of them!" on your
    Christmas list.

    But even if it's only one per second, you'll get 86400 per
    day. Can you read 86400 E-mails in one day? Can you find the
    four "different" stack traces among those 86400? Remember: You
    have ONE second to make up your mind about each of them, if you
    don't want to fall behind! Less, if you're monitoring more than
    one Java environment ... Try this experiment: Turn off all your
    spam filters, and opt out of any that your ISP offers, and tell
    us how smoothly you deal with the onslaught.

    Another little matter: At a rate of >= 1 E-mail/second, many
    mail servers will say "Spammer!" and refuse to cooperate. What
    are the chances that any of the "interesting" E-mails will be
    among those that get through before the boom is lowered?

    If you're in a position to write `catch' blocks to separate
    the "possibly interesting" from "certainly boring" exceptions,
    java.util.logging.Handler has sufficient hooks to spew info to
    an agent that will E-mail it. But ALL exceptions!? I can't think
    of any way (even in principle) to do that with a stock JVM, and
    I can't imagine that you'd get anything usable out of it.

    --
    Eric Sosman
    d
    Eric Sosman, Dec 12, 2013
    #11
  12. RVic

    Eric Sosman Guest

    On 12/11/2013 9:09 PM, Eric Sosman wrote:
    > On 12/11/2013 6:23 PM, RVic wrote:
    >> On Wednesday, December 11, 2013 5:55:34 PM UTC-5, RVic wrote:
    >>> Is anyone aware of a public domain package that can email you on an
    >>> error, include the stack trace or log, whenever an exception occurs?
    >>> Thank you, RVic

    >>
    >> Looking to send an email on exceptions that are caught, and a general
    >> one for those that are uncaught.
    >>
    >> I dont mind if there are a ton of emails!

    >
    > I honestly do not know how many exceptions are thrown each
    > second in a "typical" Java program. [...]


    .... but I found a twelve-year-old paper about optimizing both
    the exceptional and unexceptional execution paths ("A Study of
    Exception Handling and Its Dynamic Optimization in Java," by
    Ogasawara, Komatsu, and Nakatani). It contains a table counting
    how many exceptions are thrown by various programs. Some excerpts:

    - Web browser opening one (2001-vintage) page: 2,892 exceptions
    - MP3 player starting and loading one file: 8,205 exceptions
    - Parse one XML file (size? complexity?): 17,640 exceptions
    - One program in SPECjvm98 (now obsolete): 242,318 exceptions

    Now: Speaking slowly, distinctly, and directly into the
    carnation in my buttonhole, explain once again that you "dont
    mind if there are a ton of emails."

    --
    Eric Sosman
    d
    Eric Sosman, Dec 12, 2013
    #12
  13. On 12/11/2013 08:08 PM, Arne Vajhøj wrote:
    > On 12/11/2013 6:13 PM, Eric Sosman wrote:
    >> On 12/11/2013 5:55 PM, RVic wrote:
    >>> Is anyone aware of a public domain package that can email you on an
    >>> error, include the stack trace or log, whenever an exception occurs?

    >>
    >> I think you'd have to modify the JVM itself to do this. But
    >> you wouldn't want to: If you got an E-mail for every exception
    >> thrown, you'd drown in E-mail.
    >>
    >> Presumably, what you really want is E-mail about "important"
    >> exceptions, and the hard part is clarifying what "important" means.
    >> Could you describe your use case in more detail?

    >
    > In theory exceptions should be for exceptional cases meaning
    > no drowning in emails.
    >
    > I have seen many apps where your concerns are valid though.
    >
    > Arne
    >

    It's true that exceptions are for exceptional cases. The Java tutorial
    says that:

    "An exception is an event, which occurs during the execution of a
    program, that disrupts the normal flow of the program's instructions."

    However, as you yourself admit, Arne, there are many apps where there
    are frequent exceptions. And no small number of these apps are actually
    well-designed.

    As an example (and this is based on a setup I am familiar with),
    consider an ESB app that mediates between 2 systems: A and B. System A
    is a source of data for system B, but both are unaware of each other,
    and the data must be transformed before it goes into B. The hitch is,
    the ESB app has no ability to do more than very simple validation, and
    System A has a fair bit of bad data, because of human data entry and
    configuration reasons [1]. Hence, System B must validate (because it
    knows what it can accept), and this works OK.

    The validation errors must come back to the ESB app, since the ESB app
    is the controlling intelligence. They come back as SOAP faults (Java
    runtime exceptions), which is appropriate.

    Furthermore, the ESB app polls System A, and communicates with System B
    using SOAP, every few minutes (this interval being configurable but
    dictated by business requirements).

    So the first few months we were getting a few dozen SOAP faults every
    few minutes, so say about 500-1000 every hour, or 10-20 thousand a day.

    Thing is, 99 percent of those 10-20 thousand SOAP faults were for the
    same few dozen bad data entries in System A. Sending an email for each
    of those would have overwhelmed the human recipients. We recognized that
    a separate ESB job that ran every 24 hours (and effectively called the
    same intermediary logic) would capture all the problems, and it could
    send out a *single* email that provided a summary of the bad data in
    system A (and why it was bad).

    Point being, email notification on errors (as with logging errors to
    file etc) are almost always going to a human being [2]. As such, the
    urgency of an error dictates whether a notification should be sent at
    all, how often an email should be sent, who gets it (human or system),
    the nature of the email content (summary or single event), etc etc.

    To wit, for a large percentage of apps I think an "email per exception"
    strategy will lead to drowning in emails. And you can Splunk or
    grep|uniq|cut|cat|paste all that to your hearts's content...essentially
    wasting your time to do what the reporting systems could have done in
    the first place.

    AHS

    1. The fixes for which, in a unionized and bureaucratic environment, are
    not simple.

    2. I suppose you could send a stringified object reference to a CORBA
    client... :)
    --
    When a true genius appears, you can know him by this sign:
    that all the dunces are in a confederacy against him.
    -- Jonathan Swift
    Arved Sandstrom, Dec 13, 2013
    #13
  14. RVic

    Arne Vajhøj Guest

    On 12/13/2013 11:44 AM, Arved Sandstrom wrote:
    > On 12/11/2013 08:08 PM, Arne Vajhøj wrote:
    >> On 12/11/2013 6:13 PM, Eric Sosman wrote:
    >>> On 12/11/2013 5:55 PM, RVic wrote:
    >>>> Is anyone aware of a public domain package that can email you on an
    >>>> error, include the stack trace or log, whenever an exception occurs?
    >>>
    >>> I think you'd have to modify the JVM itself to do this. But
    >>> you wouldn't want to: If you got an E-mail for every exception
    >>> thrown, you'd drown in E-mail.
    >>>
    >>> Presumably, what you really want is E-mail about "important"
    >>> exceptions, and the hard part is clarifying what "important" means.
    >>> Could you describe your use case in more detail?

    >>
    >> In theory exceptions should be for exceptional cases meaning
    >> no drowning in emails.
    >>
    >> I have seen many apps where your concerns are valid though.
    >>
    >> Arne
    >>

    > It's true that exceptions are for exceptional cases. The Java tutorial
    > says that:
    >
    > "An exception is an event, which occurs during the execution of a
    > program, that disrupts the normal flow of the program's instructions."
    >
    > However, as you yourself admit, Arne, there are many apps where there
    > are frequent exceptions. And no small number of these apps are actually
    > well-designed.
    >
    > As an example (and this is based on a setup I am familiar with),
    > consider an ESB app that mediates between 2 systems: A and B. System A
    > is a source of data for system B, but both are unaware of each other,
    > and the data must be transformed before it goes into B. The hitch is,
    > the ESB app has no ability to do more than very simple validation, and
    > System A has a fair bit of bad data, because of human data entry and
    > configuration reasons [1]. Hence, System B must validate (because it
    > knows what it can accept), and this works OK.
    >
    > The validation errors must come back to the ESB app, since the ESB app
    > is the controlling intelligence. They come back as SOAP faults (Java
    > runtime exceptions), which is appropriate.
    >
    > Furthermore, the ESB app polls System A, and communicates with System B
    > using SOAP, every few minutes (this interval being configurable but
    > dictated by business requirements).
    >
    > So the first few months we were getting a few dozen SOAP faults every
    > few minutes, so say about 500-1000 every hour, or 10-20 thousand a day.
    >
    > Thing is, 99 percent of those 10-20 thousand SOAP faults were for the
    > same few dozen bad data entries in System A. Sending an email for each
    > of those would have overwhelmed the human recipients. We recognized that
    > a separate ESB job that ran every 24 hours (and effectively called the
    > same intermediary logic) would capture all the problems, and it could
    > send out a *single* email that provided a summary of the bad data in
    > system A (and why it was bad).
    >
    > Point being, email notification on errors (as with logging errors to
    > file etc) are almost always going to a human being [2]. As such, the
    > urgency of an error dictates whether a notification should be sent at
    > all, how often an email should be sent, who gets it (human or system),
    > the nature of the email content (summary or single event), etc etc.
    >
    > To wit, for a large percentage of apps I think an "email per exception"
    > strategy will lead to drowning in emails. And you can Splunk or
    > grep|uniq|cut|cat|paste all that to your hearts's content...essentially
    > wasting your time to do what the reporting systems could have done in
    > the first place.


    Well - I am not convinced that the exception is the right choice
    when the data quality is as it is resulting in 10-20 thousand
    exceptions per day.

    But that type of scenario is seen frequently.

    But given the question, then I am not expecting the original
    poster to be working on that type of application.

    Arne
    Arne Vajhøj, Dec 14, 2013
    #14
  15. On 12/14/2013 05:36 PM, Arne Vajhøj wrote:
    > On 12/13/2013 11:44 AM, Arved Sandstrom wrote:
    >> On 12/11/2013 08:08 PM, Arne Vajhøj wrote:
    >>> On 12/11/2013 6:13 PM, Eric Sosman wrote:
    >>>> On 12/11/2013 5:55 PM, RVic wrote:
    >>>>> Is anyone aware of a public domain package that can email you on an
    >>>>> error, include the stack trace or log, whenever an exception occurs?
    >>>>
    >>>> I think you'd have to modify the JVM itself to do this. But
    >>>> you wouldn't want to: If you got an E-mail for every exception
    >>>> thrown, you'd drown in E-mail.
    >>>>
    >>>> Presumably, what you really want is E-mail about "important"
    >>>> exceptions, and the hard part is clarifying what "important" means.
    >>>> Could you describe your use case in more detail?
    >>>
    >>> In theory exceptions should be for exceptional cases meaning
    >>> no drowning in emails.
    >>>
    >>> I have seen many apps where your concerns are valid though.
    >>>
    >>> Arne
    >>>

    >> It's true that exceptions are for exceptional cases. The Java tutorial
    >> says that:
    >>
    >> "An exception is an event, which occurs during the execution of a
    >> program, that disrupts the normal flow of the program's instructions."
    >>
    >> However, as you yourself admit, Arne, there are many apps where there
    >> are frequent exceptions. And no small number of these apps are actually
    >> well-designed.
    >>
    >> As an example (and this is based on a setup I am familiar with),
    >> consider an ESB app that mediates between 2 systems: A and B. System A
    >> is a source of data for system B, but both are unaware of each other,
    >> and the data must be transformed before it goes into B. The hitch is,
    >> the ESB app has no ability to do more than very simple validation, and
    >> System A has a fair bit of bad data, because of human data entry and
    >> configuration reasons [1]. Hence, System B must validate (because it
    >> knows what it can accept), and this works OK.
    >>
    >> The validation errors must come back to the ESB app, since the ESB app
    >> is the controlling intelligence. They come back as SOAP faults (Java
    >> runtime exceptions), which is appropriate.
    >>
    >> Furthermore, the ESB app polls System A, and communicates with System B
    >> using SOAP, every few minutes (this interval being configurable but
    >> dictated by business requirements).
    >>
    >> So the first few months we were getting a few dozen SOAP faults every
    >> few minutes, so say about 500-1000 every hour, or 10-20 thousand a day.
    >>
    >> Thing is, 99 percent of those 10-20 thousand SOAP faults were for the
    >> same few dozen bad data entries in System A. Sending an email for each
    >> of those would have overwhelmed the human recipients. We recognized that
    >> a separate ESB job that ran every 24 hours (and effectively called the
    >> same intermediary logic) would capture all the problems, and it could
    >> send out a *single* email that provided a summary of the bad data in
    >> system A (and why it was bad).
    >>
    >> Point being, email notification on errors (as with logging errors to
    >> file etc) are almost always going to a human being [2]. As such, the
    >> urgency of an error dictates whether a notification should be sent at
    >> all, how often an email should be sent, who gets it (human or system),
    >> the nature of the email content (summary or single event), etc etc.
    >>
    >> To wit, for a large percentage of apps I think an "email per exception"
    >> strategy will lead to drowning in emails. And you can Splunk or
    >> grep|uniq|cut|cat|paste all that to your hearts's content...essentially
    >> wasting your time to do what the reporting systems could have done in
    >> the first place.

    >
    > Well - I am not convinced that the exception is the right choice
    > when the data quality is as it is resulting in 10-20 thousand
    > exceptions per day.


    It is however the right choice for SOAP. Altering the body to introduce
    error result codes introduces extra coupling between systems; SOAP
    faults (which translate into Java runtime exceptions) are the standard
    way of handling data validation errors, among other things.

    That one system has poor data doesn't change this.

    > But that type of scenario is seen frequently.


    You betcha. :)

    > But given the question, then I am not expecting the original
    > poster to be working on that type of application.
    >
    > Arne


    I'm not convinced that he is or isn't, Arne. The OP seemed to be
    ostensibly OK with handling high volumes of emails...although that may
    be seriously optimistic on his part.

    AHS
    --
    When a true genius appears, you can know him by this sign:
    that all the dunces are in a confederacy against him.
    -- Jonathan Swift
    Arved Sandstrom, Dec 15, 2013
    #15
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. eddie wang

    ASP catch exception

    eddie wang, Jul 24, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    4,406
    eddie wang
    Jul 24, 2003
  2. John Black
    Replies:
    8
    Views:
    4,130
    Xenos
    Aug 20, 2004
  3. Adam
    Replies:
    9
    Views:
    542
    red floyd
    Feb 2, 2006
  4. Keith G Hicks
    Replies:
    1
    Views:
    352
    Keith G Hicks
    Apr 28, 2008
  5. Marteno Rodia

    catch doesn't catch a thrown exception

    Marteno Rodia, Aug 3, 2009, in forum: Java
    Replies:
    5
    Views:
    540
    Daniel Pitts
    Aug 5, 2009
Loading...

Share This Page