Hi I'm supposed to make a Java Programm for school and I'm stuck creating a function that throws a custom exception.
public class ParkingSpace implements ParkingPlace {
private Automobile P_Car;
public void placeCar(Car car) throws NoFreePlaceException{
if(this.P_Car == null) {
throw new NoFreePlaceException(car);
}
this.P_Car = (Automobile) car;
}
}
The custom exception:
public class NoFreePlaceException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
public NoFreePlaceException() {
super("There is no free place for the current car");
}
public NoFreePlaceException(Car car) {
super ("There is no free place for the current car with plate number: " + car.getLicensePlateNumber());
}
}
But I always get an Error trying to type this.
Exception NoFreePlaceException is not compatible with throws clause in ParkingPlace.placeCar(Car) ParkingSpace.java
/NOS_LB2/src/at/fhsalzburg/its/nos/parksim line 41 Java Problem
I'm supposed to make this implementation just like that according to my Professor. I'm quite versed in C++ but still relatively new to Java.