Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/03/2010, 00:32
KKarloss
 
Fecha de Ingreso: junio-2007
Mensajes: 53
Antigüedad: 17 años, 5 meses
Puntos: 0
Excepciones y variables de clase

Buenas.

Tengo un problema a la hora de ejecutar una excepción cuyo mensaje está definido como variable de clase .

No se como hay que llamarla, asi al compilar me da error:

public void addVehiculo(Vehiculo vehiculo) {
if(this.Vehiculos.contains(vehiculo)){
throw new GarageException.VEHICLE_ALREADY_IN;
}
else if(this.Vehiculos.size() == this.MaxNumVehiculos){
throw new GarageException.GARAGE_FULL;
}
else{
this.Vehiculos.add(vehiculo);
}
}
-------------------------------------------------------------------
La clase GarageException es esta:


public class GarageException extends Exception {

/**
*
*/
private static final long serialVersionUID = 1L;
/**
* When the vehicle is already in the garage.
*/
public static String VEHICLE_ALREADY_IN = "The Vehicle is already inside the garage.";
/**
* When the vehicle is not in the garage.
*/
public static String VEHICLE_NOT_IN = "The Vehicle is not inside the garage.";
/**
* When the garage is full.
*/
public static String GARAGE_FULL = "The garage is full.";

/**
*
*/
public GarageException() {
super("This is a generic GarageException");
}

/**
* @param arg0
*/
public GarageException(String arg0) {
super(arg0);
}
}
-------------------------------------------------------------------------------------------------------
y la clase main es esta:

public class Mostrador {

public Mostrador() {
}
/**
* Comentamos la linea de la instanciación y salida estandar de la clase
* vehiculo para evitar errores de compilación.
* @param args the command line arguments
*/
public static void main(String[] args) {
Garage g = new Garage("MyParking", 2);
Coche c1 = new Coche(4, 140, 4.30, 2.30, "1234BCD");
Coche c2 = new Coche(4, 140, 4.30, 2.30, "2234BCD");
Motocicleta m = new Motocicleta(2, 50, 2.25, 0.70, "9876DCB");
try {
g.addVehiculo(c1);
}
catch (GarageException ge){
System.err.println("An error has occurred: " + ge.toString());
}

try {
g.addVehiculo(c1);
}
catch (GarageException ge) {
System.err.println("An error has occurred: " + ge.toString());
}

try {
g.addVehiculo(c2);
}
catch (GarageException ge) {
System.err.println("An error has occurred: " + ge.toString());
}

try {
g.addVehiculo(m);
}
catch (GarageException ge) {
System.err.println("An error has occurred: " + ge.toString());
}

try {
g.removeVehiculo(c1.getPlate(), 60);
}
catch (GarageException ge) {
System.err.println("An error has occurred: " + ge.toString());
}

try {
g.removeVehiculo(c1.getPlate(), 60);
}
catch (GarageException ge) {
System.err.println("An error has occurred: " + ge.toString());
}

try {
g.addVehiculo(m);
}
catch (GarageException ge) {
System.err.println("An error has occurred: " + ge.toString());
}

try {
g.removeVehiculo(c2.getPlate(), 120);
}
catch (GarageException ge) {
System.err.println("An error has occurred: " + ge.toString());
}

try {
g.removeVehiculo(m.getPlate(), 30);
}
catch (GarageException ge) {
System.err.println("An error has occurred: " + ge.toString());
}

}
}