swing - How to remove part of a message java.lang.IllegalArgumentException on Excpetion handling -
i'm developping swing application, form on process several validations using exceptions. knowing since java 7 possible utilize mutli-catch statement, used improve code, since stacktrace begins :
"java.lang.exeption :" + handling exception message.
how remove "java.lang.exeption :" of message ?
here illustration of validations , execution.
actionevent:
public void actionperformed(actionevent arg0){ //validation 1 nomegrupovazio(string1); //validation 2 validastring(string2); //validation 3 diferenciarrms(int1, int2, int3, int4); }
valitadions:
private void nomegrupovazio(string nome) { if (nome.isempty()) { throw new illegalargumentexception("preencha o nome grupo!"); } } private void validastring(string s) { pattern pattern = pattern.compile("[0-9]"); matcher matcher = pattern.matcher(s); if (matcher.find()) { throw new illegalargumentexception( "por favor digite apenas caracteres não numéricos nos campos referentes aos nomes"); } } private void diferenciarrms(int rm1, int rm2, int rm3, int rm4) { if (rm4 == 0) { if (rm1 == rm2 || rm1 == rm2 || rm1 == rm3 || rm2 == rm3) { throw new illegalargumentexception( "todos os rm's precisam ser diferentes"); } } else if (rm1 == rm2 || rm1 == rm3 || rm1 == rm4 || rm2 == rm3 || rm2 == rm4 || rm3 == rm4) { throw new illegalargumentexception( "todos os rm's precisam ser diferentes"); }
thanks in advance!
i guess, using exception#tostring()
exception message. seek using exception#getmessage()
instead.
exception ex = new illegalargumentexception("my error message!"); system.out.println(ex.tostring()); system.out.println(ex.getmessage());
hope helps.
java swing exception-handling java-7
No comments:
Post a Comment