java - Continue the execution after exception -


i have these 2 class :

public class tryexception {     int a=0;      tryexception(int c) {         = c;     }      public boolean operation() //just example     {         if(a!=10)         {             system.out.println(a);             return true;         }else{             throw new runtimeexception("display something");         }      }  } 

and main :

public class test {     static public void main(string args[])     {         int val =20;         tryexception ex = new tryexception(val);          try{             while(ex.operation()){                 ex.a = --val;             }          }catch(runtimeexception e)         {             system.out.println("try exception");         }     } } 

when run program, execution stoped when detects exception. how continue execution of same while after exception ?

move try-catch inside loop.

 boolean run = true;  while(run){     ex.a = --val;     try{        run = ex.operation();     }catch(runtimeexception e){         system.out.println("try exception");     }      } 

you need decide when set run false...


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -