Courseiva

1Z0-829 · domain

Handling Exceptions

Practise Oracle Certified Professional Java SE 17 Developer 1Z0-829 Handling Exceptions practice questions — original exam-style scenarios with answer choices, explanations, and analysis of common mistakes.

49 questions13 easy19 medium17 hard

Focused practice

Practice Handling Exceptions questions

Scored sessions drawing only from this domain — pick a length below.

Start 20-question practice test →

What this domain covers

What to know about Handling Exceptions

Handling Exceptions questions test whether you can apply the concept in context, not just recognise a definition.

How the topic appears in realistic exam-style scenarios.

Which detail in the question changes the correct answer.

How to eliminate plausible but wrong options.

How to connect the question back to the wider exam objective.

Watch out for

Common Handling Exceptions exam traps

  • Answering from memory before reading the full scenario.
  • Missing a constraint such as cost, availability, security, scope or command context.
  • Choosing a broad answer when the question asks for the most specific fix.
  • Ignoring why the wrong options are tempting.

Question index

All Handling Exceptions questions (49)

Click any question to see the full explanation, or start a practice session above.

1

A method catches multiple exceptions using a multi-catch clause. Which statement about the exceptions in a multi-catch clause is correct?

Hard
2

Which of the following is a checked exception in Java?

Easy
3

Given the following assertion: assert age >= 0 : "Age must be non-negative"; When is it appropriate to use assertions?

Hard
4

Consider try-with-resources where resource1 is opened first, then resource2. During closing, both throw exceptions. Which exception is propagated to the caller?

Hard
5

Which of the following is a best practice when designing custom exception classes?

Easy
6

A financial trading application uses Java 17 and processes millions of transactions per second. It uses a custom checked exception `TradeException extends Exception` for business rule violations. Recently, the transaction processing service began throwing a `RuntimeException` that wraps a `TradeException`, but the error logs only show the wrapper's message and stack trace, missing the original `TradeException` details. The logging framework prints the exception and its cause chain. The development team needs to ensure that the original `TradeException` message and stack trace are always logged. What is the most appropriate course of action?

Hard
7

Which THREE statements about exception handling are true? (Choose three.)

Easy
8

Given an exception chain where a custom exception is created with a cause, which method is used to set the cause after construction?

Hard
9

Given the stack trace, which statement is true about the exception handling?

Hard
10

In a try-finally block, what happens to a return statement inside the finally block?

Easy
11

A team is designing a logging framework. The framework's core method log(String message) may throw a checked LogException if the logging system fails. The team wants to allow callers to choose whether to handle the exception or declare it as thrown. Which declaration of the log method satisfies this requirement?

Easy
12

Given the exhibit showing output from a program that uses try-with-resources, which of the following best describes the program?

Hard
13

What is the output when the code is executed?

Medium
14

Given a method that throws IOException, SQLException, and TimeoutException, a developer writes a catch block that rethrows the exception. Using Java 17, which exception types can the catch block declare in its throws clause if the rethrown exception is not modified?

Hard
15

Given a try-with-resources statement where both the try block and the close method of the resource throw exceptions, which of the following is true about exception handling?

Hard
16

Given the following code snippet inside a method: try { // risky code } catch (IOException | SQLException e) { // handle } What is the implicit type of the exception variable 'e' in the catch block?

Medium
17

Which THREE practices are recommended for effective exception handling? (Choose three.)

Hard
18

Which TWO statements about creating custom exceptions are correct? (Choose two.)

Hard
19

Which TWO of the following are checked exceptions in Java?

Medium
20

Which TWO statements about try-with-resources are true? (Choose two.)

Medium
21

Your team manages a high-throughput financial transaction system running on Java 17. Recently, the application experiences intermittent slowdowns and increased CPU usage during peak hours. Monitoring reveals that exception handling code is invoked frequently due to validation errors in incoming data. The system uses a central exception handler that logs every exception and throws a custom ApplicationException. In many places, the code catches generic Exception and rethrows the custom exception after logging. Additionally, method signatures include throws Exception. The team wants to improve performance and maintainability without changing the external behavior significantly. Which course of action best addresses the performance and maintainability issues?

Hard
22

Which TWO statements about the try-with-resources statement are correct? (Choose two.)

Hard
23

What happens when a finally block throws an exception?

Easy
24

Given the exhibit showing a compilation error at line 5 of Test.java, which of the following code fragments could be at that line?

Medium
25

Which TWO of the following are unchecked exceptions? (Choose two.)

Easy
26

You are developing a microservice that processes financial transactions. The service reads transaction data from a message queue, validates it, and writes results to a database. The code uses a try-with-resources statement to manage database connections. During testing, you notice that when a transaction fails validation, the service throws an IllegalStateException before closing the database connection, causing a resource leak. You need to ensure that the database connection is always closed properly, even if an exception is thrown during validation. The current code structure is: try (Connection conn = DriverManager.getConnection(url, user, pass)) { // read from queue // validate transaction // if invalid, throw new IllegalStateException("Invalid transaction"); // write to database } Which course of action would you recommend?

Easy
27

You are developing a batch processing application that reads records from a CSV file and parses each row into an integer ID. The reading method readNextRecord() returns a String and can throw IOException and NumberFormatException. The method processID(int id) processes the ID. The entire process runs in a for loop over 10,000 records. The requirement is that if any record fails (either due to file read error or parsing), the loop must continue to the next record, but the exception must be logged for later review. Which approach best achieves this requirement?

Easy
28

Order the steps to compile and run a simple Java program from the command line.

Medium
29

A method reads a file and throws IOException. Which of the following is the correct way to declare the method?

Easy
30

You are responsible for a Java 17 application that processes user uploads. The application uses a custom AutoCloseable resource, UploadSession, which must always be closed after use to free server resources. A junior developer wrote the following code: ``` UploadSession session = new UploadSession(); try { session.upload(data); // more processing } catch (UploadException e) { log.error("Upload failed", e); } finally { session.close(); } ``` During a code review, you notice that the close() method of UploadSession throws a checked CloseException. The current code does not handle this exception. Which course of action should you recommend to ensure the application is robust and follows best practices?

Hard
31

A Java application uses a custom resource class implementing AutoCloseable. The close() method throws a checked exception. In a try-with-resources block, if both the try block and the close() method throw exceptions, which exception is propagated to the caller? Assume the resource is declared in try-with-resources.

Medium
32

Which TWO statements about the try-with-resources statement are true? (Choose two.)

Easy
33

Which TWO are valid multi-catch statements in Java 17? (Choose two.)

Hard
34

Consider the following code snippet: try { // some code } catch (IOException e) { // handle } catch (FileNotFoundException e) { // Line X // handle } What will be the result?

Medium
35

Which of the following is a checked exception in Java?

Easy
36

Given the code in the exhibit, which of the following is true about this custom exception?

Easy
37

Which of the following is a best practice when creating a custom exception class?

Medium
38

A developer is writing a method that reads a file and processes its content. The method must ensure that if an IOException occurs during reading, the method throws a custom ApplicationException that wraps the original IOException, and that any resources opened are closed properly. Which approach correctly implements this requirement?

Medium
39

A developer is implementing a method that reads a file and parses its contents. The method should ensure that any resources opened during the process are properly closed, even if an exception occurs. Which approach guarantees resource closure with minimal code?

Medium
40

Match each JDBC type to its corresponding Java type.

Medium
41

What is the result when the main method is executed?

Medium
42

Which TWO statements about try-with-resources are correct? (Choose two.)

Medium
43

In the following try-with-resources block, resources are declared as: try (FileInputStream fis = new FileInputStream("data.txt"); BufferedInputStream bis = new BufferedInputStream(fis)) { ... } If an IOException occurs during the closing of both resources, which resource's close exception is returned by e.getSuppressed()?

Hard
44

Consider the following code: public void process() throws Exception { try { riskyMethod(); } catch (IOException | SQLException e) { throw e; } } Assuming riskyMethod() declares both IOException and SQLException, what is the result?

Medium
45

You are developing a microservice that processes order payments. The service uses a custom exception hierarchy: PaymentException (checked), InsufficientFundsException (unchecked, extends RuntimeException), and NetworkException (checked, extends PaymentException). The processPayment method is declared as: public void processPayment(Order order) throws PaymentException. Inside, a call to an external payment gateway may throw InsufficientFundsException or NetworkException. The requirement is to log all payment failures to an audit system, but the service must continue processing other orders. The audit logging method is: public void logFailure(String message) throws Exception. Which approach best handles exceptions while meeting the requirements?

Hard
46

A company has a service layer with a method performOperation() that originally declared throws BaseException (a checked exception). Several client methods call performOperation() and catch BaseException, wrapping it in a RuntimeException for propagation. After a system upgrade, the implementation of performOperation() now explicitly throws two new checked exceptions: SubException1 and SubException2, both of which extend BaseException. The client methods must continue to compile without modifying their catch signatures, and they must still handle the new exceptions appropriately. What is the best way to modify the client methods?

Medium
47

Which two statements about multi-catch blocks are correct?

Medium
48

A developer wants to ensure that a block of code always executes regardless of whether an exception occurs or not, and that any exception thrown in the block is not swallowed. Which construct should be used?

Medium
49

What is the result of executing the code in the exhibit?

Medium

Frequently asked questions

What does the Handling Exceptions domain cover on the 1Z0-829 exam?
Handling Exceptions questions test whether you can apply the concept in context, not just recognise a definition.
How many questions are in this domain?
This page lists all 49 Handling Exceptions questions in the 1Z0-829 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
What is the best way to practise this domain?
Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
Can I practise only Handling Exceptions questions?
Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.
Oracle Certified Professional Java SE 17 Developer 1Z0-829 Handling Exceptions Practice Questions