The reason for the compile error of "unreachable code" is that Java checks that the statements behind them cannot be executed unless
Because jumping to the next loop, or somewhere else, could not execute the next sentence because of a constant cycle of death. These errors are called compile-time errors
Checked exception: This type of exception is a subclass of exception
Unchecked exception: This type of exception is a subclass of RuntimeException
1. Throw keyword
Java code:
1 Public void throws throwable{ 2 thrownew throwable (); 3 SYSTEM.OUT.PRINTLN ("test"); 4 }
2. return keyword
Java code:
Public void XXX () { return; System.out.println ("test"); }
3. Continue keyword
Java code:
1 Public void XXX () { 2 for (int i=0; i<10; i++) { 3 continue; 4 SYSTEM.OUT.PRINTLN ("test"); 5 } 6 }
4. break keyword
Java code:
Public void XXX () { for (int i=0; i<10; i++) { if(i==5) { Break ; System.out.println ("test"); }}}
5. while (true):
Java code:
Public Static void XXX () { while(true); System.out.println ("when?");
Java will show several examples of "Unreachable code" errors