Foros del Web » Programación para mayores de 30 ;) » Java »

Excepciones y variables de clase

Estas en el tema de Excepciones y variables de clase en el foro de Java en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 16/03/2010, 00:32
 
Fecha de Ingreso: junio-2007
Mensajes: 53
Antigüedad: 16 años, 10 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());
}

}
}
  #2 (permalink)  
Antiguo 16/03/2010, 03:16
Avatar de elAntonie  
Fecha de Ingreso: febrero-2007
Mensajes: 894
Antigüedad: 17 años, 2 meses
Puntos: 10
Respuesta: Excepciones y variables de clase

Wenas

Logico

Código:
throw new GarageException(GarageException.GARAGE_FULL);
__________________
--
NO. Tu problema no es urgente.

CCFVLS
  #3 (permalink)  
Antiguo 16/03/2010, 03:49
 
Fecha de Ingreso: junio-2007
Mensajes: 53
Antigüedad: 16 años, 10 meses
Puntos: 0
Respuesta: Excepciones y variables de clase

Gracias, es que soy un poco bruto.

Saludos.

Etiquetas: clase, excepciones, variables
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:11.