1Z0-829 Controlling Program Flow Practice Question
A Java developer is writing a batch processing application that reads records from a database and processes them. The processing must continue even if some records cause exceptions (e.g., data conversion errors). However, the application must log each failed record and its error, then continue with the next record. The developer uses a for loop to iterate over a list of records. Inside the loop, a try-catch block wraps the processing logic. After implementing, the developer notices that when an exception occurs, the loop terminates prematurely instead of continuing. The code structure is:
List<Record> records = fetchRecords();
for (Record rec : records) {try { process(rec);
} catch (Exception e) {log.error("Failed to process: " + rec.getId(), e);
} }
What is the most likely reason for the premature termination?
⚠ Common exam trap
Watch out — candidates often assume all exceptions are caught by `catch (Exception e)`, forgetting that `Error` is a separate branch of `Throwable` and is not caught by that handler, leading to premature loop termination when an `Error` is thrown.
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
✓
The process() method throws an Error instead of an Exception.
The code catches `Exception`, but `Error` (and its subclasses like `OutOfMemoryError`, `StackOverflowError`, or custom `Error` types) are not subclasses of `Exception`. In Java, `Throwable` has two main branches: `Exception` (including `RuntimeException`) and `Error`. Since `Error` is not caught by `catch (Exception e)`, it propagates up and terminates the loop. This is the most likely reason for premature termination because the developer assumed all failures would be `Exception` types.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
The records list contains null elements, causing a NullPointerException that is not caught.
Why it's wrong here
NullPointerException is an Exception, so it would be caught.
- ✓
The process() method throws an Error instead of an Exception.
Why this is correct
Errors are not caught by catch(Exception), causing the loop to terminate.
- ✗
The log.error() method itself throws an unchecked exception that is not caught.
Why it's wrong here
If log.error throws an unchecked exception, it would propagate out of the catch block and terminate the loop, but this is less likely than an Error from process().
- ✗
The try-catch block is incorrectly placed inside the for loop, causing the loop to break on any exception.
Why it's wrong here
The try-catch inside the loop is correct for continuing after exceptions; it does not cause termination.
Go deeper
Related to this question
About these practice questions
Courseiva writes every 1Z0-829 question from scratch — 513 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 1Z0-829 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-829 exam.