Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider how an uncaught exception in a thread is handled. Which statement is correct?

  • A.An uncaught exception is handled by the thread group only, since threads have no handler of their own.
  • B.An uncaught exception is handled by the thread's own handler, then its group, then the default handler.
  • C.An uncaught exception is handled only by the handler set with setDefaultUncaughtExceptionHandler().
  • D.An uncaught exception is passed to the parent thread's catch blocks.

Answer: B

Handling is controlled first by the thread, via setUncaughtExceptionHandler, then by its ThreadGroup's uncaughtException method, and finally by the default handler. The chain is why a per-thread handler overrides a default one that is already installed.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.