File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jxam question

 
Himanshu Jhamb
Ranch Hand
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Macon Pegram
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic