try {
while (true) {
//略
if (key == null) {
throw new MyException("Stop Serching.");
}
//略
if (key.length() == 0) {
throw new MyException("Enter any characters.");
}
//略
}
} catch (Exception e) {
System.out.println(e.getMessage());
}

こういう事?