aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Exceptions thrown by wait(). Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Exceptions thrown by wait()." Watch "Exceptions thrown by wait()." New topic
Author

Exceptions thrown by wait().

geetha nagarajan
Ranch Hand

Joined: Jul 13, 2001
Posts: 94
Question from Javacaps sample test :2.
Select all the exceptions thrown by wait() method of an Object class, which you can replace in the place of xxx legally?

The answer is given as :
catch ( InterruptedException ie) {}
catch ( IllegalArgumentException il ) {}
catch ( IllegalMonitorStateException im ) {}
Does wait() throw IllegalArgumentException ?
I thought wait() throws only InterruptedException and IllegalMonitorStateException.
Pl.clarify.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
IllegalArgumentException is a runtime exception. Therefore, a method that throws it need not declare it and you can catch it at any time.
Corey


SCJP Tipline, etc.
Swati Gupta
Ranch Hand

Joined: May 28, 2002
Posts: 106
The parameter to wait() method is either (long msec) or (long msec, int nanosec)
If this parameter is not proper (as in this case it is -ve) the wait() methos will throw IllegalArgumentException.
Suresh Thota
Ranch Hand

Joined: Sep 24, 2003
Posts: 152
Hi all,
Resurfacing a old thread. Please see the question above. This is from java caps mock - 2.
Though IllegalArgumentException & IllegalMonitorStateException are legal exceptions thrown by the wait() method, InterruptedException is a checked exeption which comes under handle or declare rule. But as only one of the exception's can replace XXX, it should be InterruptedException. isn't it? I think the answer should be only InterruptedException. someone please clarify.
Cheers
-Suresh


SCJP 1.6
Kurankyi Dadson
Greenhorn

Joined: Mar 12, 2004
Posts: 14
The question says 'legally' not 'appropriately' so the best way to verify is to insert the code and see waht the compiler says. I should imagine that it will permit even the unchecked exceptions.
Kurankyi Dadson
Greenhorn

Joined: Mar 12, 2004
Posts: 14
Just tried it. You can catch the other two exceptions in addition but MUST catch the InterruptedException. So the one Interrupted will appear to be the right answer
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Exceptions thrown by wait().