Given an exception chain where a custom exception is created with a cause, which method is used to set the cause after construction?
Allows setting the cause after construction.
Why this answer
`initCause(Throwable)` is the method provided by the `Throwable` class to set the cause of an exception after the exception has been constructed. This is useful when the exception must be created without a cause (e.g., via a no-arg constructor) and the cause is determined later. The cause can only be set once; a second call will throw an `IllegalStateException`.
Exam trap
The trap here is that candidates confuse `initCause(Throwable)` with `addSuppressed(Throwable)`, or assume the cause can only be set via constructor, missing the post-construction capability that `initCause` provides.
How to eliminate wrong answers
Option A is wrong because the cause can be set both via a constructor (e.g., `Throwable(String message, Throwable cause)`) and after construction using `initCause(Throwable)`. Option B is wrong because there is no method named `setCause(Throwable)` in the `Throwable` class or any standard Java exception class; the correct method is `initCause(Throwable)`. Option C is wrong because `addSuppressed(Throwable)` is used to add suppressed exceptions (typically in try-with-resources) and does not set the causal chain; it adds exceptions that were suppressed, not the root cause.