my dog learned polymorphism*
The moose likes Beginning Java and the fly likes try...catch blocks giving <identifier> expected error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "try...catch blocks giving <identifier> expected error" Watch "try...catch blocks giving <identifier> expected error" New topic
Author

try...catch blocks giving <identifier> expected error

John Weiss
Greenhorn

Joined: Feb 05, 2010
Posts: 2
Hi everyone,
I've been working on some code and am trying to get exception handling to work in a few places. But whenever i put in the try catch blocks i get a compile error. I've been looking at this for hours and still can't figure it out. Does anybody have any ideas?

Here's my compiler errors:

jbw_OfficeTest.java:35: <identifier> expected
catch(InputMismatchException){

jbw_OfficeTest.java:61: <identifier> expected
catch(InputMismatchException){


Here's my code:
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18497
    
  40

John Weiss wrote:Here's my compiler errors:

jbw_OfficeTest.java:35: <identifier> expected
catch(InputMismatchException){

jbw_OfficeTest.java:61: <identifier> expected
catch(InputMismatchException){




Your syntax is incorrect. Take a look at some examples in the Java exceptions tutorial, and you'll see that you are missing something.

http://java.sun.com/docs/books/tutorial/essential/exceptions/

Henry
John Weiss
Greenhorn

Joined: Feb 05, 2010
Posts: 2
Ahhh, I sure do feel dumb now. Thanks a ton!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37884
    
  22
also search for InputMismatchException on this forum; you will find ways to avoid it completely. Maybe here, or here, and while we are at it, here is a different pitfall with Scanner.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: try...catch blocks giving <identifier> expected error
 
Similar Threads
Java noob -- sentinel-controlled while loop
Else without if error
Please Help! Having problems with class program
Error problems
How to input End of File indicator