• Post Reply Bookmark Topic Watch Topic
  • New Topic

valueChanged can't throw SQLException??

 
Jeremiah Elliott
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thanks. That got it working.
-J
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!