I would like to check user input value against a declared final variable to make sure it does not exceed the final int variable for the purpose of using in a try-catch-finally.

final int variable = 20; // Variable declared for max allowable
int userInput = 0; // Used to hold user input from GUI interface
try {
userInput > variable; // This does not work
}
catch (ArithmeticException e) {
System.out.println("Your input exceeds max allowble.");
}
finally {
System.out.println("Good, input does not exceed max allowable.");
}
}

You have to use an if test in some form or another.
If you really want to use catch/finally to handle it you can throw a new Exception, as in

if (somethingIsWrong) throw new Exception("Something went wrong");

(although some writers think you shouldn't use exceptions for ordinary user errors)

You have to use an if test in some form or another.
If you really want to use catch/finally to handle it you can throw a new Exception, as in

if (somethingIsWrong) throw new Exception("Something went wrong");

(although some writers think you shouldn't use exceptions for ordinary user errors)

Great thanks - I will close now.

This question has already been answered. Start a new discussion instead.