The Artima Developer Community
Sponsored Link

Java Answers Forum
problem with try/catch block

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
edwin mo

Posts: 7
Nickname: ct976
Registered: Oct, 2002

problem with try/catch block Posted: Oct 11, 2002 5:20 AM
Reply to this message Reply
Advertisement
this while loop works, but it just doesnt catch the exception.. can anyone see whats wrong?
i am supposed to catch the exception if an illegal lunch is entered in readLunch(), and discard it from the lunches array if its illegal. if its not, continue reading the array

while (!done) {
try {
lunches[numLunches] = readLunch();
numLunches++;
}
catch (Lunch.IllegalLunchFieldException e) {
System.out.println (e.getMessage());
// deletes the illegal lunch just entered
lunches[numLunches] = lunches[numLunches-1];
// decrement illegal lunch
numLunches--;
} // end try-catch block

if (numLunches == MAX_LUNCHES)
done = true;
else {
System.out.print("enter more lunches (y/n)? ");
done = !readBoolean();
} // end if

} // end while

Topic: can some teach me how to do palindrome this is wat i have Previous Topic   Next Topic Topic: Can not back to previous page.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use