• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Designing with exception handling

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings all,

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?
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic