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

Related Questions

Is there any way I can detect when a line break has been erased
Resharper does not detect if a method has been generated by user or VS.
I know that richtextboxes can detect links (like http://www.yahoo.com ) but is there a
Is there a way ActionScript 3 can detect the user's screen resolution?
A there any g++ options which can detect improper initialization of std::string with NULL
Is there anyway that we can detect when the system/screen gets locked and notify
I know a simple URLConnection to google can detect if I am connected to
Is there any way that I can detect browser type on routing and use
I was wondering how I can detect code plagiarism with Javascript. I want to
Is there a way in which I can detect the URL that is calling

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.