• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Exception question.

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In regards to exceptions, which of the following are true?

a) An exception can be thrown by a no argument constructor.

b) An exception can only be thrown by a multi argument constructor.

c) Uncaught exceptions should be listed in the throws clause of a class definition.

d) In all cases except exiting the JVM, the finally clause of a try block is executed.

are the answers a and d. what is the meaning of d?
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Jaman,

i think D is talking about System.exit(1); In this case the finally cluase will not be executed
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding answer d :



If you execute this code, "finally-1" will be printed, ok ?
(This demonstrate "In all cases, the finally clause of a try block is executed")
But if you uncomment the line System.exit(0), there's no output (JVM exiting before finally block can be executed).

Hope that hepls.
 
jaman tai
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh, you are right! , thanx!
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the finally clause of a try block is executed regardless catch or uncatch exception .Except exit JVM by system.exit(1).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic