Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 38877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:46:37+00:00 2026-05-10T14:46:37+00:00

How can I detect when an Exception has been thrown anywhere in my application?

  • 0

How can I detect when an Exception has been thrown anywhere in my application?

I’m try to auto-magically send myself an email whenever an exception is thrown anywhere in my Java Desktop Application. I figure this way I can be more proactive.

I know I could just explicitly log and notify myself whenever an exception occurs, but I’d have to do it everywhere and I might(more likely will) miss a couple.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:46:37+00:00Added an answer on May 10, 2026 at 2:46 pm

    You probobly don’t want to mail on any exception. There are lots of code in the JDK that actaully depend on exceptions to work normally. What I presume you are more inerested in are uncaught exceptions. If you are catching the exceptions you should handle notifications there.

    In a desktop app there are two places to worry about this, in the event-dispatch-thread (EDT) and outside of the EDT. Globaly you can register a class implementing java.util.Thread.UncaughtExceptionHandler and register it via java.util.Thread.setDefaultUncaughtExceptionHandler. This will get called if an exception winds down to the bottom of the stack and the thread hasn’t had a handler set on the current thread instance on the thread or the ThreadGroup.

    The EDT has a different hook for handling exceptions. A system property 'sun.awt.exception.handler' needs to be registerd with the Fully Qualified Class Name of a class with a zero argument constructor. This class needs an instance method handle(Throwable) that does your work. The return type doesn’t matter, and since a new instance is created every time, don’t count on keeping state.

    So if you don’t care what thread the exception occurred in a sample may look like this:

    class ExceptionHandler implements Thread.UncaughtExceptionHandler {   public void uncaughtException(Thread t, Throwable e) {     handle(e);   }    public void handle(Throwable throwable) {     try {       // insert your e-mail code here     } catch (Throwable t) {       // don't let the exception get thrown out, will cause infinite looping!     }   }    public static void registerExceptionHandler() {     Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler());     System.setProperty('sun.awt.exception.handler', ExceptionHandler.class.getName());   } } 

    Add this class into some random package, and then call the registerExceptionHandler method and you should be ready to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 180k
  • Answers 181k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can simply call "open appname.app" in the Terminal. So… May 12, 2026 at 4:09 pm
  • Editorial Team
    Editorial Team added an answer you have a bug on the line "FROM @authorIds.nodes('/Authors/value') as… May 12, 2026 at 4:09 pm
  • Editorial Team
    Editorial Team added an answer Check out NSFormatter. It can help you do what you're… May 12, 2026 at 4:09 pm

Related Questions

I've never been completely happy with the way exception handling works, there's a lot
A RIA Domain service has this method... public virtual CmsDealer GetCmsDealer(string id) { return
What I would like to know is the definite approach to encrypting connection strings
I need to be able to detect if flash was the originator of a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.