• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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{}.
 
Hey cool! They got a blimp! But I have a tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic