Re: [HELP]Java Exceptions
The Exception being thrown is probably NumberFormatException
Enclose that part with a try and catch. Also you could check the stack trace what's the actual error that is being thrown.
Re: [HELP]Java Exceptions
I have a hunch that an ArrayIndexOutOfBoundsException is more likely to happen..
Anyway, instead of catching the exception you need to be checking the input
Re: [HELP]Java Exceptions
Avoid a one liner... check first if index 3 exists.
Re: [HELP]Java Exceptions
Code:
else if(splitted[0].equals("!addpoints")) {
try { MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
int points = Integer.parseInt(splitted[3]);
victim.setPoints(points);
mc.dropMessage(victim.getName()+" successfully credited with "+points+" points");
} catch(IndexOutOfBoundsException smiles) {
mc.dropMessage("Syntax: !addpoints <Charname> <Amount of Points>");
} catch(NumberFormatException ioerror) {
mc.dropMessage("A number should be given o.o");
}
}
So caught two exceptions. So shouldnt it show the Message if splitted[3] doenst exist and if the points amount is a non-integer value?
Re: [HELP]Java Exceptions
I can think of a dozen or more exception that might be thrown, you need to check the user input instead of handling system exceptions
Re: [HELP]Java Exceptions
you mean something like
Code:
if(splitted.length > 3 || splitted.length< 3) {
mc.dropMessage("Incorrect command syntax");
} else {
//code
}
this?
Re: [HELP]Java Exceptions
Yes, something like that
I don't know what you're trying to accomplish exactly. But checking user input is more effective than waiting for an Exception to be thrown
Re: [HELP]Java Exceptions
This is a game simulator written in Java. It takes in commands inputted by the user and proccesses them. This particular code enables gamemasters to give / remove points from users...
ill try implementing that ^^
Re: [HELP]Java Exceptions
Based on variable name splitted, I'll assume you used the split method which uses a regular expression as split criteria... if so, then you can use the matches method to check user input, e.g. you can check if a split group contains only numeric digits before actually performing the split.