How do I throw an exception to check a character inYou don't. That isn't the purpose of exceptions. You throw the exception AFTER you check the character, if there is some reason to do so.
I'm trying to create an if statement where it canFirst, stop thinking of exceptions as the tool to check the characters. Stick with the if-statements.
check in a string for certain characters. And when
the character statements are met an exception has to
So far I've had no luck creating the if statement.
Can someone help me out?
The string cannot have '-', '_', and no numbers.
String val; if(!(val.equals("A")) || val.equals("B")) || val.equals("C")) || val.equals("D")) || val.equals("E")) || val.equals("F")) ) throw new IllegalArgumentException("letters");