Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Try-catches cannot be found

 
James Palmer
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what do you mean by 'find' the catch? Be specific on the expected behavior and the observed behavior.
 
James Palmer
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
} 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
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic