Unreachable code is part of the source code of a program which can never be executed because there exists no control flow path to the code from the rest of the program.
Questions tagged [unreachable-code]
181 questions
-2
votes
2 answers
Why this code is showing "unreachable code" error?? And how can I fix it?
public class Array {
public static void main(String[] args) {
int[] arr= {5,6,9,-5,-2,4,-3,1,-1};
int i=0;
int n=arr.length;
int j=n-1;
while(true)
while(arr[i]>0 && i

Saksham
- 3
- 1
-2
votes
1 answer
Unreachable code from if-statement about String checks
For some reason I get an error that the line currentUser = gar.getAccount(userN); is unreachable and yet it shouldn't be. Garage.getAccount() is just a retrieval from a Hashmap. Both if statements don't counter each other and I've tried adding else…

ToastyHaymaker
- 1
- 2
-2
votes
1 answer
Exception Class declared but not thrown
Here test is not throwing an Exception object , yet i had handled it . Since Exception is an checked exception shouldn't it throw a compiler error of unreachable code in the catch block
class Ece extends Exception {}
public class Excep {
public…

Yash Singhal
- 357
- 1
- 2
- 8
-2
votes
1 answer
Why is this unreachable code?
Got a practice question, and I have the below code:
while (false) { x=3; }
The x=3 is unreachable code, and I don't really understand why. There is a similar section of code:
if (false) { x=3; }
which is perfectly valid.
May be a bit of a noob…

Sam
- 223
- 3
- 7
-2
votes
2 answers
Java 8 Unreachable Code
I am fairly new to Java and I ran into this problem once or twice in one of my books. This is a super simple program and I just don't understand why it's not working. I know when you use return, anything after it in the method is meaningless. So…

killerx615
- 45
- 1
- 4
-2
votes
6 answers
Unreachable Statement with this boolean
I'm getting an unreachable statement error with this boolean declaration.
I know unreachable usually means meaningless, but I need the isValid statement for my while loop to work. Why am I getting this error and how can I fix it? Here is my…

tonno5309
- 23
- 4
-2
votes
3 answers
Unreachable Code - return startId;
I'm attempting to add some functionality to my source code to log the fact at least one phone call has been made before I execute the rest of my code (which collects total amount of wifi and cell data usage and sends it via sms) however when I added…

user2528574
- 41
- 1
- 3
- 7
-3
votes
1 answer
Why i get error "unreachable code" when i try to put an if in my function?
When i insert "if (descriptions >= 0.4){zien()} then it gets red underlined with error "unreachable code". Why is that??
function loadLabeledImages() {
const labels = ['Simon', 'Thomas'];
return Promise.all(
labels.map(async (label) => {
…
user17489239
-3
votes
1 answer
Catch block avoid Compilation Error?
I have the following codes, and it is giving me a compilation error.
// Program1 -- Compilation error
public class ExceptionExample {
public static void main(String[] a) {
try {
method();
} catch (ClassCastException…

prudhvi yallanki
- 1
- 2
-3
votes
4 answers
Unreachable code when I'm already calling it
I have to do some kind of Google Maps like program on Java, I have the following code:
public double CGlon(double graus, double min, double sec)
{
double min2;
graus =(int) longitud;
min = (longitud - graus)*60;
…

manutheking
- 25
- 4
-4
votes
2 answers
Unreachable code detected in Switch
I am using a switch and get a warning that code is unreachable.
If control goes to case 2 or 3, something will get execute then what is the issue?
user3180869
-4
votes
2 answers
Unreachable Code - Anything put inside if statement
I've searched this question here before asking and all of the answers seem to be people putting code after return break or others. I am having an issue where no matter what I put in an if statement, the code reads that it is unreachable.
private…

mkamin15
- 37
- 4
-4
votes
7 answers
Unreachable Code Java Compilation Error
I have searched many topics for my problem, read a lot... but they were not exactly as mine.
I'm getting the "Unreachable Code" compilation error from Eclipse IDE.
I don't understand why my code is unreachable! It is simple though!
Here it…

MiDOZ
- 1
- 1
- 2
-5
votes
2 answers
Unreachable code ; i dont understand why it is unreachable
import java.util.Scanner;
public class start {
public static void main(String[] args) {
System.out.println("time to pick a name! type in your desired option");
System.out.println("1: Harry");
System.out.println("2:…

Caitlin Craik
- 121
- 1
- 2
- 4
-6
votes
2 answers
Unreachable code
public void onClick(View v) {
String uname=tv1.getText().toString();
String pass=tv2.getText().toString();
//String copmare=uname.concat(pass);
Cursor cur = db.query("accountTable", // Where are we looking?
new String[]{…

irfan
- 1