Courseiva
Exception Handling and Development ToolshardMultiple ChoiceObjective-mapped

1Z0-811 Exception Handling and Development Tools Practice Question

A team is designing a library that handles network timeouts. They create a custom exception `NetworkTimeoutException` that extends `Exception`. They want to ensure that callers are forced to handle this exception. Which declaration is appropriate for a method that throws this exception?

⚠ Common exam trap

Many candidates confuse the `throw` keyword (used to throw an exception in code) with the `throws` keyword (used in method declarations), and assuming that declaring a superclass like `RuntimeException` satisfies the requirement to declare a specific checked exception.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

public void connect() throws NetworkTimeoutException

The method must declare the custom checked exception `NetworkTimeoutException` in its throws clause to force callers to handle it. Since `NetworkTimeoutException` extends `Exception` (not `RuntimeException`), it is a checked exception, and the Java compiler enforces that any method throwing it must declare it with the `throws` keyword followed by the exception type name.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • public void connect() throws RuntimeException

    Why it's wrong here

    RuntimeException is unchecked; callers are not forced to handle it, which defeats the purpose of a custom checked exception.

  • public void connect() throws NetworkTimeoutException

    Why this is correct

    Correct syntax: checked exception declared with `throws` forces callers to handle or declare it.

  • public void connect() throws e where e is NetworkTimeoutException

    Why it's wrong here

    Invalid syntax: `throws` clause must contain the exception class name(s), not a variable.

  • public void connect() throw NetworkTimeoutException

    Why it's wrong here

    Incorrect syntax: method declarations use `throws` (with 's'), not `throw`.

About these practice questions

One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.