This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Try-catches cannot be found Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Try-catches cannot be found" Watch "Try-catches cannot be found" New topic
Author

Try-catches cannot be found

James Palmer
Ranch Hand

Joined: Mar 15, 2004
Posts: 36
Hello
My problem is i ve made a program and when i compile it the try cannot find the catch and the catch cannot find the previous try...
The program is a bit lke this:
try {
for (; { //the door starts from closed,opens completely and then closes again with this code:

int waitPeriod = 1000; //time between each change of state of lift door
if ((current_state == STAGE0) && (opening = true)) {
current_state = STAGE1;
door[0] = (byte)STAGE1_OUTPUT;
try{ Thread.sleep(waitPeriod); } catch (Exception e) {}
doorPort.write(door, 0, 1);
}
.
.
more code
.
.
else if ((current_state == STAGE1) && (opening = false)) {
current_state = STAGE0;
door[0] = (byte)STAGE0_OUTPUT;
doorPort.write(door, 0, 1);
try{ Thread.sleep(waitPeriod); } catch (Exception e) {}
}
} catch (IllegalAddressException e) {
System.out.println(e.toString());
System.exit(0);
}
}

****
The try at the start cannot find the catch at the end and vice-versa.I ve checked the brackets a few times and they seem right.Its driving me mad!!
Thanks for the help.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

what do you mean by 'find' the catch? Be specific on the expected behavior and the observed behavior.
James Palmer
Ranch Hand

Joined: Mar 15, 2004
Posts: 36
It gives me 2 errors.The first one is that there is a try without catch and the second one is that there is a catch without a try.I have both but one can't find the other.
Gabriel White
Ranch Hand

Joined: Mar 02, 2003
Posts: 233
} catch (IllegalAddressException e) {

This line has no try associated with it. You will have to use a try within a try if you want this to work.
Eddie Vanda
Ranch Hand

Joined: Mar 18, 2003
Posts: 281
Hi John,
This is a good illustration of goes wrong without proper indenting. Nothing seems to match correctly.
I use textpad and with ctl/m I can see where each bracket matches. No doubt your IDE has a similar service.
If you indent correctly, you can spot non matching brackets much more easily.


The nice thing about Standards is that there are so many to choose from!
 
wood burning stoves
 
subject: Try-catches cannot be found