java - Why does this exception not cause a runtime error? -


i have following code in practice question:

public class test {      static string s = "";      public static void m0(int a, int b) {          s += a;          m2();         m1(b);     }      public static void m1(int i) {         s += i;     }      public static void m2() {         throw new nullpointerexception("aa");      }      public static void m() {         m0(1, 2);          m1(3);     }      public static void main(string args[]) {         try {             m();          } catch (exception e) {         }         system.out.println(s);     } } 

at method m2, when nullpointerexception thrown, why not terminate thread expected? thought there not try catch block in same method, cause exception , halt program.

as understand it, has reverted called method, m0, when thought thrown exception have halted program. end result program prints 1, value of s.

everything have read far concerning exceptions doesn't explain logic, , can't work out myself, hoping help! in advance.

when nullpointerexception thrown, why not terminate thread expected?

because thread not going terminate unless exception travels way invocation chain.

i thought there not try catch block in same method, cause exception , halt program.

it's not same method, it's in of methods chain of invocation - in case, main catches exception, preventing thread terminating.


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -