Estoy realizando un ejercicio de herencias y de trhow extends exception y me encuentro con una serie de problemas.
De primeras, por una parte tengo el siguiente archivo:
public class Product {
private int referenceId = 0;
private String reference;
private String name;
private int publicationYear;
private String description;
private double price;
private ProductException productexception;
public Product() throws ProductException{
setName("Lorem Ipsum");
setPublicationYear(2011);
setDescription("lorem ipsum description");
setPrice(7.50);
createReference();
}
public Product(String name, int publicationYear,String description, double price) throws ProductException{
setName(name);
setPublicationYear(publicationYear);
setDescription(description);
setPrice(price);
createReference();
}
public String getName() {
return name;
}
public void setName(String name) throws ProductException{
if (name.length() > 50) {
throw new ProductException(productexception.MSG_ERR_NAME);
} else {
this.name = name;
}
}
El otro archivo, donde tengo las exepciones es el siguiente:
public class ProductException extends Exception {
public static String MSG_ERR_NAME = "[ERROR] Team's name cannot be longer than 50 characters";
public static String MSG_ERR_PUBLICATION_YEAR = "[ERROR] Product's publicationYear cannot be later than current year";
public static String MSG_ERR_DESCRIPTION = "[ERROR] Product's description cannot be longer than 250 characters";
public static String MSG_ERR_NEGATIVE = "[ERROR] Product's price cannot be negative";
El problema es que no acabo de llamar bien el archivo de las expeciones en el constructor y no entiendo el porque.
En el primer throw new, me salta el error de "Expected 0 arguments but found 1".
Alguna ayuda?
Gracias