Will a java exception terminate the whole java application? -
i used think when exception happened, whole java application terminated. example, write test function test idea.
public void test(){ file filedir=new file(sourcedatadir); if(filedir.exists()){ file[] files = filedir.listfiles(); for(int index=0 ; index<files.length ; index++){ system.out.println("index = "+index); file file = files[index]; if(index == 1)//delete file cause filenotfoundexception file.delete(); try { bufferedreader in = new bufferedreader(new filereader(file)); } catch (filenotfoundexception e) { e.printstacktrace(); } } } }
i delete file cause filenotfoundexception
manually. used think whole application terminate when exception happened. in fact, application continue reading remaining files. so, question is, in condition exception cause whole application terminated?
my question ,in condition ,a exception cause whole application terminated?
it won't ever. system.exit() causes whole program terminate (and jvm crash)
think of exception , powerful break;
can break out of methods. break result in loop exiting , if last loop in non daemon thread, program exit. doesn't cause it, though might last thing see before program dies.
Comments
Post a Comment