Good guys, I told you my problem. I am practicing the subject of the exceptions in java and I have changed some of the validations that I have to replace them with exceptions but I have a problem and I do not know how to implement a second exception. I show you the part of the code where I have the problem:
public static void main(String[] args) {
boolean flag = false;
float sueldo = 0;
while (!flag) {
try {
System.out.println("Introduce el sueldo");
sueldo = MyInput.readFloat();
flag = true;
} catch (NumberFormatException nfe) {
System.out.println("Error. El valor introducido no es correcto. Intentelo de nuevo...");
}
}
}
Well, that part of the exception is well placed and well implemented. The idea is that in case the salary that is entered is correct (the value is numeric) another exception is thrown if the value of that variable is < 500. I have already created a new class called "SalaryException" that inherits from the Exception class but I do not know how to implement it in the code that I have shown you before
public class SalarioExcepcion extends Exception{
private float sueldo;
public SalarioExcepcion(float sueldo) {
super();
this.sueldo = sueldo;
}
public String getMensaje() {
String mensaje = null;
if (this.sueldo <= 500) {
mensaje = "Error. El sueldo del empleado ha de ser como MINIMO 501 €";
}
return mensaje;
}
}
Any idea how I can do it if it is possible?
Thank you very much.