Tuesday, September 15, 2015

Orphaned case error in Java Switch case

Orphaned Case Error in Java is one of the rarest errors you can see in Java. You can see this error  in cases like


  • When you write your case statements outside your switch statement. 

 switch (var) {  
       case 1:  
       //some code here....  
       break;   
 }  
   case 2:  
       //some code here....  
       break;


  • If by mistake if you terminated your switch testaments unexpectedly 


 switch (var); { <--- statement terminated by ;   
     case 1:   
     //some code here....   
     break;    
  }  

And in another case  where a case statement doesn't belong to switch and became orphan.


Note : Errors like this won't be seen if you are using an IDE since they compile your code on the fly and show the error message immediately, only traditional compilers will show this error, when you compile through your command line.






Post a Comment