catch without try

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2009
Posts: 6
Reputation: nonshatter is an unknown quantity at this point 
Solved Threads: 0
nonshatter nonshatter is offline Offline
Newbie Poster

catch without try

 
0
  #1
30 Days Ago
Can anyone shed some light on these errors?
  1. public void FaultHandler () {
  2. int faultCount = 0;
  3. while ( faultCount < 4 ) {
  4. DatagramPacket request =
  5. new DatagramPacket(requestArray, requestArray.length, aHost, proxyPort);
  6. aSocket.send(request);
  7. try {
  8. aSocket.setSoTimeout(4000);
  9. aSocket.receive(reply);
  10. }
  11. catch ( SocketTimeoutException e ) {
  12. faultCount++;
  13. continue;
  14. }
  15. catch ( IOException e ){}
  16. break;
  17.  
  18. catch ( IOException e ) {} //----it doesn't like this line!
  19. if ( faultCount >= 3 )
  20. System.exit(0);
  21. }
  22. }

I keep getting these errors:

'catch' without 'try'
catch ( IOException e ) {}
^
Ex2Client.java:18: ')' expected
catch ( IOException e ) {}
^
Ex2Client.java:18: not a statement
catch ( IOException e ) {}
^
Ex2Client.java:18: ';' expected
catch ( IOException e ) {}
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster
 
0
  #2
30 Days Ago
Walk through and match up your braces.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 972
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 145
JamesCherrill JamesCherrill is offline Offline
Posting Shark
 
1
  #3
30 Days Ago
The "break" on line 16 is outside any catch, so it terminates the list of catches associated with the previous try. So the catch on line 18 hasn't got a try to match to.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 26
Reputation: Cronless is an unknown quantity at this point 
Solved Threads: 2
Cronless Cronless is offline Offline
Light Poster
 
1
  #4
30 Days Ago
In addition to the "break" comment above, which is dead-on, you also can't catch the same exception twice in a try clause...you're catching IOException a second time after the break.
~~ Free Cron Jobs - Online Cron Service ~~
Best place to run your PHP Cron Jobs
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC