• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception question.

 
jaman tai
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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?
 
premraj cheguri
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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
 
Seb Mathe
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
oh, you are right! , thanx!
 
Mandy Hou
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic