NoClassDefFoundError ncdx2 = null;
try {
...
} catch(NoClassDefFoundError ncdx) {
ncdx2 = ncdx;
}
if(ncdx != null) {
System.out.println("Try again: " + ncdx.getMessage());
} else {
next = true;
}
This works, but it is definitely not recommended to use a the absence of an error as the terminating condition for a loop. Is there any way to check this without having to crash? Hopefully the API you are using has some information about some isOkeyDokey()
function or something. If not, you could probably do some reflection. Anything is better than using an error as a replacement for logic.
More information: https://www.google.com/search?q=how+to+catch+an+error+in+java