Throw an exception from actionPerformed() method.

A

Asanka

Hi All,

I am developing a Java application with Swing and Oracle. On the way I
want to throw an exception from the actionPerformed() method of an
ActionListener.

But I can't do that because it doesn't implement it in the
ActionListener interfacre. Is there any way to do that.

Say doPopulate populates a table and essentially it wants to throw or
catch SQLException. So I can't call it like this way.



ActionListener act = new ActionListener(){
public void actionPerformed(ActionEvent ae){
doPopulate();
}
};

But I want to throw it some way without catching..

Could you please advice me how to throw that exception (without
catching)..

Many Thanks ...

Asanka Francis...
 
M

Michael Rauscher

Asanka said:
Hi All,

I am developing a Java application with Swing and Oracle. On the way I
want to throw an exception from the actionPerformed() method of an
ActionListener.

But I can't do that because it doesn't implement it in the
ActionListener interfacre. Is there any way to do that.
No.


Say doPopulate populates a table and essentially it wants to throw or
catch SQLException. So I can't call it like this way.



ActionListener act = new ActionListener(){
public void actionPerformed(ActionEvent ae){ try {
doPopulate();
} catch ( SQLException se ) {
ExceptionHandler.getInstance().handleException( se );
}

Where ExceptionHandler is an appropriate class.

Bye
Michael
 
N

Nigel Wade

Asanka said:
Hi All,

I am developing a Java application with Swing and Oracle. On the way I
want to throw an exception from the actionPerformed() method of an
ActionListener.

But I can't do that because it doesn't implement it in the
ActionListener interfacre. Is there any way to do that.

Say doPopulate populates a table and essentially it wants to throw or
catch SQLException. So I can't call it like this way.



ActionListener act = new ActionListener(){
public void actionPerformed(ActionEvent ae){
doPopulate();
}
};

But I want to throw it some way without catching..

Could you please advice me how to throw that exception (without
catching)..

You can't. You have to catch it and handle it.

What do you think the EDT would do with the exception if you actually managed to
get the ActionListener to throw it? How do you think your GUI would behave from
then on?
 
A

Asanka

Nigel said:
You can't. You have to catch it and handle it.

What do you think the EDT would do with the exception if you actually managed to
get the ActionListener to throw it? How do you think your GUI would behave from
then on?

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : (e-mail address removed)
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555

Hi Nigel,

Actually I wanted to handle it from somewhere else..

But with your reply I got to know that there then there is a
mishappening in the GUI.

Now I think about it again,,

Many Thanks ..

Asanka.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top