• 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

Mock exam question on exception

 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Every try block must have a corresponding catch block
A True
B False

Well! The answer i choosed was true but mock exam says its false.
Mock explaination: A try block can be associated with either a catch block or a finally block or both.

a) I cant have a try { }finally { } correct? If try{} is throwing a compile time exception the above code will fail to compile.

b) I can have try{} finally{} compiles fine.

c) I can have try{} catch(RunTimeException e) { } , This will work even because the catch block is having a runtimeexception and not a compile time exception which would then cause a compiler error if try{} doesnt throw the compile time exception.

Does this mean the mock exam answer is correct?
Thanks
Deepak
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have a try, it should be followed by either a catch or finally. You can omit one but not both.
 
Ranch Hand
Posts: 99
Mac Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer of the mock exam is absolutely alright.
It is not necessary to write a catch{} block with try{}, but you must provide either catch{} or finally{} block with try{}.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic