wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Jxam question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Jxam question" Watch "Jxam question" New topic
Author

Jxam question

Himanshu Jhamb
Ranch Hand

Joined: Aug 01, 2001
Posts: 134
Hi.
I encountered the following question in Jxam.
----------------------------------------------
Suppose a MyException should be thrown if Condition() is true, which statements do you have to insert ? Select all correct Answers
1: public aMethod {
2:
3: if (Condition) {
4:
5: }
6:
7: }
A) throw new Exception() at line 4
B) throws new MyException() at line 4
C) throw new MyException() at line 6
D) throws new Exception() at line 2
E) throws MyException at line 1
----------------------------------------
My answer was only E).
Jxam says answer is E) & B)
I tested it out with jdk1.3 & got the following result when I plugged in choice B) in the code.
ExceptionHandling.java:6: illegal start of expression
I think this is probably a typo error by the Jxam developer. There is an additional 's' in the choice B).
The choice B) should read as follows ...
B) throw new MyException() at line 4
- Himanshu


Himanshu Jhamb<br />SCJP2 v1.2 (April 2002)<br />SCJP2 v1.4 (May 2002)
Macon Pegram
Greenhorn

Joined: Mar 01, 2002
Posts: 12
It is a typo... B should read:
throw new MyException()
not "throws". "throws" indicates possible exceptions a method may throw (and is used as part of the method definition. "throw" is used to explicitly throw an exception.
I would have agreed with you that only E was correct given the options.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Jxam question