• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jxam question

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic