I'm currently in the process of learning how to properly do custom exception and I stumbled upon a problem. Whenever I try to utilize an object of a class that throws this custom exception, my IDE's debugger (I'm using IntelliJ idea) says "Unhandled Exception: InsertExceptionName()". The code, in a simplified manner, looks something like this. In this case, it should return an exception if the randomly generated number is <0.5, and return a number otherwise, but it won't do that. What am I missing?
public class main {
public static void main(String[] args) {
double x=Math.random();
operation op=new operation();
op.execute(x);
}
}
-
public class operation {
public operation() {
}
public double execute(double x) throws RandomWeirdException {
if(x<0.5) {
throw new RandomWeirdException("<0.5");
}
return x;
}
}
-
public class RandomWeirdException extends Exception{
public RandomWeirdException() {
super();
}
public RandomWeirdException(String message) {
super(message);
}
}