Which of the following is a best practice when creating a custom exception class?
Standard practice for custom exceptions that represent programming errors.
Why this answer
Extending RuntimeException is the standard way to create a custom unchecked exception in Java. Unchecked exceptions do not require explicit handling via try-catch or throws clauses, making them suitable for programming errors like invalid arguments or illegal states. This aligns with Java's exception hierarchy where RuntimeException and its subclasses are unchecked.
Exam trap
The trap here is that candidates may think extending Throwable directly is acceptable for creating a new exception type, but the Java Language Specification recommends extending Exception or RuntimeException to maintain consistency with the standard hierarchy and avoid confusing checked/unchecked semantics.
How to eliminate wrong answers
Option A is wrong because Exception is a class, not an interface; Java does not have an 'Exception interface' to implement. Option B is wrong because extending Error is reserved for serious system failures (e.g., OutOfMemoryError) that applications should not attempt to handle or create custom subclasses of. Option D is wrong because extending Throwable directly is discouraged; it bypasses the established Exception and Error hierarchy, leading to non-standard exception types that are neither checked nor unchecked in a conventional sense.