This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
I have a tricky problem that I wonder if anyone has a solution for. I have lots of GUI classes and another class which implements ActionListener and has an actionPeformed method. Now what I wanted to do was have only 1 try catch block in my code. This try catch block I wanted to place in my main method. Problem is my actionPerformed method contains a call to a method that throws an exception. I don't want to catch the exception in the actionPerformed method (as that will break my design such that it is) and I can't put a throws clause in the header of the actionPerformed method as this would mean that I'm not actually implemented the ActionListener interface. Anyone have a solution to this?
I don't know what to tell you other than that this "design" isn't workable. Exceptions propagate within a single thread only, and the GUI thread is different from the one in which main() lives.
Now, what you want, really, is centralized error reporting, and that is a good thing. There are many alternatives, but they all boil down to having one reporting method you can simply call from any catch block you write. That reporting method might throw up an error dialog, or log the error using log4j, or both, or something else altogether.