• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

valueChanged can't throw SQLException??

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
swing nooby question:
I have an interface that has a JList, and several other components. When the user chooses an item in the list the data in the other components should change. I have a method that will update all the dependent components, and it works unless I invoke the method from the valueChanged() method. It gives me an error "unreported exception java.sql.SQLException". If I throw the SQLException however it says

So is there a better way to do this than updating the other components from the valueChanged() method? Or is there way to allow valueChanged() to throw other exceptions?
--thanks in advance.
Jeremiah Elliott
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to override the valueChanged() method of the ListSelectionListener it must not throw any exception.
In general, it makes no sense for listener methods to throw an exception. You have to handle that in the Listener class. The event dispatching class that notifies its listeners is not interested in what its listeners will do when they get notified, nor whether they might throw some exception.
Moreover, you have to catch the exception anyway to assure that the GUI doesn't crash because of it and to inform the user, that something didn't go as planned. If you are certain that the SQLException only happens as result of programming errors, than catch it and throw some RuntimeException instead.
cheers
Chantal
 
Jeremiah Elliott
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks. That got it working.
-J
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic