
-----------------------------------
Chinmay
Mon Jan 07, 2008 6:37 pm

the exit phrase
-----------------------------------
:oops: 

Ok I have a if block inside a try block as such:



try {

     if ("Hey".equals("hey") {
          System.out.print("The above two are equal, which they are not!");
     } else {
          exit;
     }

}




why would this gimme an syntax error and not exit the if and after ending the try block?

-----------------------------------
HeavenAgain
Mon Jan 07, 2008 6:45 pm

RE:the exit phrase
-----------------------------------
simple, its because thats not how you use try. look at the exception tut for detail about try & catch.
int your case, you do not need try at all, so your code will simply be
     if ("Hey".equals("hey") 
          System.out.print("The above two are equal, which they are not!");
     else
          System.out.println("they are not equal, because i am right");

if you MUST use exit, the syntax is System.exit(int status), unless you import static System class, you cannot just say exit, and static import is only supported in java1.6 i believe :roll:
