Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/04/2010, 12:30
liderzen
 
Fecha de Ingreso: abril-2010
Mensajes: 3
Antigüedad: 14 años
Puntos: 0
Manejo de excepcion dentro de addActionListener

Mi duda es la siguiente:

Quiero lanzar una excepcion cuando el retiro de una cuenta sea mayor al saldo disponible.

En el boton Retirar hago lo siguiente:

btnRetirar.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)throws RetiroException
{
double saldo=MappedCuentas.obtenerSaldo(Integer.parseInt( txtId.getText()));
double retiro = Double.parseDouble(txtRetiro.getText());
lblSaldoAnteriorDato.setText(String.valueOf(saldo) );
if(retiro <= saldo)
{
saldo = saldo - retiro;
lblSaldoActualDato.setText(""+saldo);
MappedCuentas.guardarCuenta(Integer.parseInt(txtId .getText()),saldo);
}
else
{
throw new RetiroException("NO SE PUEDE REALIZAR EL RETIRO");
}
}
});

mi Clase RetiroException:

public class RetiroException extends Exception
{


public RetiroException(String mensaje)
{
super(mensaje);
}


}

me sale el siguiente error:

actionPerformed(java.awt.event.actionEvent) n cannot implement actionPerformed (java.awt.event.actionEvent) in java.awt.event.actionListener; overridden method does not throw RetiroException

Quisiera saber que estoy haciendo mal o si no es posible lanzar la excepción que quiero.. Soy novato en java

MUCHAS GRACIAS!!!!