QCM - Subsection 7.8: Indentation (Partie 5)
Quiz interactif avec 5 questions. Testez vos connaissances!
Comment jouer ?
- 1. Lisez chaque question attentivement
- 2. Choisissez votre réponse parmi les options
- 3. Cliquez sur "Voir la réponse" pour vérifier
- 4. Comptez vos bonnes réponses à la fin !
Quiz: QCM - Subsection 7.8: Indentation (Partie 5)
5 questions | Difficulté: moyen
Question 1
What is the problem with catching all exceptions in the given code?
- A. The code will run faster
- B. The parent thread may wait indefinitely for the child thread to stop, leading to a deadlock
- C. The child thread will not be able to execute
- D. The child thread will run infinitely
Voir la réponse
Réponse correcte: B
Catching all exceptions can lead to a deadlock as the parent thread waits indefinitely for the child thread to stop.
Question 2
What is the solution to avoid the problem with catching all exceptions?
- A. Use a logging framework
- B. Do not catch any exceptions
- C. Catch InterruptedException individually beforehand
- D. Throw the exception up in the chain
Voir la réponse
Réponse correcte: D
It is better to throw the exception up in the chain instead of catching it.
Question 3
Why should you avoid excessive or inappropriate stacktraces?
- A. They are informative for end-users who are not Java programmers
- B. They help to identify the source of an error quickly
- C. They do not affect the performance of your code
- D. They can be uninformative at best, and alarming at worst
Voir la réponse
Réponse correcte: D
Excessive or inappropriate stacktraces can be uninformative at best, and alarming at worst for end-users who are not Java programmers.
Question 4
What is a better idea than calling printStackTrace() directly?
- A. Call printStackTrace() only in a way that the stack trace is written to standard output
- B. Do not call printStackTrace() at all
- C. Use a logging framework, and pass the exception object as a parameter of the log event
- D. Call printStackTrace() frequently
Voir la réponse
Réponse correcte: C
A better idea than calling printStackTrace() directly is to use a logging framework, and pass the exception object as a parameter of the log event.
Question 5
What should you not do when logging exceptions?
- A. Log every single exception that occurs in your code
- B. Write the stacktrace to standard output
- C. Use a logging framework, and pass the exception object as a parameter of the log event
- D. Do not log exceptions at all
Voir la réponse
Réponse correcte: B
Logging every single exception that occurs in your code can be harmful if done injudiciously.