wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes throwing exceptions in actionPerformed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "throwing exceptions in actionPerformed" Watch "throwing exceptions in actionPerformed" New topic

throwing exceptions in actionPerformed

Hung Tang
Ranch Hand

Joined: Feb 14, 2002
Posts: 148
is this possible? I have a listener class that implements ActionListener. In this class, I implement the actionPerformed method. I will attach the listener class to a button, so whenever I click on the button, the actionPerformed method will be invoked. Now, in this method, there will be code that will throw exceptions (possibly maybe reading a file, IOException) But actionPerformed signature does not allow it to throw exceptions. The compiler keeps on complaining. How do I solve this problem?
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
But actionPerformed signature does not allow it to throw exceptions.

You don't have much of a choice. You must catch your exceptions inside a try catch block and handle everything there since you cannot rethrow the exception.
[ March 29, 2002: Message edited by: Anthony Villanueva ]
I agree. Here's the link: http://aspose.com/file-tools
subject: throwing exceptions in actionPerformed
It's not a secret anymore!