validation - java parseInt exceptions not being caught -


i'm trying catch exceptions parseint request same response, if string not parse int, performs code under catch. make simple validation loop, asking them try again each time try leave field without having entered valid int. right throw exceptions in system console not return pre-configured error message , run associated code.

    public static void main(string[] args){     //draw , show gui     jframe gui = new jframe();     gui.settitle("new provider interface");     gui.setdefaultcloseoperation(jframe.exit_on_close);     final jtextfield textid = new jtextfield("providerid ", 20);     final jtextfield textname = new jtextfield("provider name ", 20);     focusgrabber fgid = new focusgrabber(textid);     gui.add(textid);     gui.add(textname);     gui.pack();     gui.setvisible(true); }      textid.addfocuslistener(new focuslistener(){ @override         public void focusgained(focusevent e) {/* */}         @override public void focuslost(focusevent e) {                 if (!e.istemporary()) {                 string  checkid = textid.gettext();                 boolean validid = false;                 if (checkid.isempty()){joptionpane.showmessagedialog(mainframe, "please enter valid id."); fgid.run();}                 else while (validid = false){try {                         string sid = textid.gettext();                         int iid = integer.parseint(sid);                     }catch (exception e1){                         joptionpane.showmessagedialog(mainframe, checkid + "is not valid id. please try again.");                         fgid.run();                     }finally {validid= true;}     }    }    }    }    ); 

the code in finally always run, if there exception.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -