Java will show several examples of "Unreachable code" errors

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.