java - Why does it not display Exception error -


      list<string> accountlist = new arraylist<string>();        accountlist.add("45678690");       accountlist.add("7878787");       scanner accountinput = new scanner(system.in);       int x = 1;  do{      try{         system.out.println("hi whats pin code?");       string value = accountinput.nextline();         (int counter = 0; counter < accountlist.size(); counter++){             if (accountlist.contains(value)){ //if input = arraylist number display "hi"               system.out.println("hi");                x = 2;           }            }  } catch (exception e){     system.out.println("you cant that");  } }while (x==1);        } }   

when run error "you cant that" not appear taken invalid , asks user re enter number untill valid, how can error line displayed?

you need throw exception able catch one:

for  (int counter = 0; counter < accountlist.size(); counter++){       if (accountlist.contains(value)) { //if input = arraylist number display "hi"         system.out.println("hi");         x = 2;     } else {         throw new exception();     } } 

edit: said in comment, line not necessary algorithm know if value contained in accountlist handled contains method.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -