Strange Compiler Error
Hello,
I'm struggling to explain a compiler error I've just received. I had some original code which looked like this:
// Begin old java file
public class Foo
{
public String f1(int x, int y) throws Exception
{
if (x == 4)
{
return "foo4";
}
else if (x == 5)
{
return "foo5";
}
else if (x == 6)
{
return "foo6";
}
else
{
throw new Exception("Uh Oh");
}
}
public static void main(String[] args) throws Exception
{
Foo foo1 = new Foo( );
System.out.println(foo1.f1(5, 8));
}
}
// end old java file
This code compiles and runs fine. I then made this modification to the code:
// begin new java file
public class Foo
{
public String f1(int x, int y) throws Exception
{
if (x == 4)
{
return "foo4";
}
else if (x == 5)
{
return "foo5";
}
else if (x == 6)
{
if (y == 7)
{
return "foo7";
}
else if (y == 8)
{
return "foo8";
}
}
else
{
throw new Exception("jason");
}
}
public static void main(String[] args) throws Exception
{
System.out.println("In main ...");
Foo foo1 = new Foo( );
System.out.println(foo1.f1(5, 8));
}
}
// End new java file
Now the compiler complains about a missing return statement in f1( ). This doesn't make sense to me, can anyone explain? Thanks in advance!
-exits

