Exception

In AP Computer Science A, an exception is an event at runtime that interrupts the normal flow of a Java program, like accessing an invalid array or ArrayList index. The AP exam tests whether you can predict WHEN code throws an exception, not how to write try-catch blocks.

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is Exception?

An exception is Java's way of saying "something went wrong while the program was running." Your code compiles fine, but at runtime an operation becomes impossible. Maybe you asked for index 5 in a list with 3 elements, divided an integer by zero, or called a method on a null reference. When that happens, Java throws an exception object, and if nothing handles it, the program stops with an error message.

Here's the AP-specific part that surprises people. AP CSA does not ask you to write try-catch blocks or create your own exception classes. Instead, the exam tests whether you can read code and predict when an exception gets thrown. The big ones to know are ArrayIndexOutOfBoundsException (arrays), IndexOutOfBoundsException (ArrayLists), NullPointerException (using a null reference), and ArithmeticException (integer division by zero). Think of exceptions as the boundary lines of the language. If you know exactly where those lines are, you know which answer choices crash and which run cleanly.

Why Exception matters in AP Computer Science A

Exceptions show up wherever index-based data structures live, mainly Unit 6 (Arrays) and Unit 7 (ArrayList), plus anywhere object references can be null. Understanding them is really a test of how well you understand bounds. An array of length n has valid indexes 0 through n - 1, and an ArrayList works the same way with size(). Off-by-one errors in loop conditions, like writing i <= list.size() instead of i < list.size(), are the single most common way AP code throws an exception. Exceptions also matter for ArrayList traversal rules. Removing an element from an ArrayList while looping over it with an enhanced for loop throws a ConcurrentModificationException, which is a classic MCQ trap. If you can spot the exact line where code crosses a boundary, you can eliminate wrong answers fast on both MCQs and FRQs.

How Exception connects across the course

IndexOutOfBoundsException (Units 6-7)

This is the most-tested specific exception on the exam. It fires when you use an index that doesn't exist, like list.get(list.size()). Almost every loop-bound question is secretly asking whether you know where this exception lives.

Unchecked Exception (RuntimeException) (Units 6-7)

Every exception AP CSA cares about (IndexOutOfBounds, NullPointer, Arithmetic, ConcurrentModification) is unchecked, meaning the compiler doesn't force you to handle it. The code compiles fine and only blows up at runtime, which is exactly why these make good MCQ traps.

Indexed for loop (Units 6-7)

The indexed for loop is where exceptions are born or avoided. The condition i < arr.length is safe; i <= arr.length throws on the last iteration. Reading the loop header carefully is half of exception prediction.

Infinite Loop (Unit 4)

These are the two big runtime failure modes you compare on the exam. An exception crashes the program loudly with a message; an infinite loop never ends and never throws anything. A loop condition that's never false gives you an infinite loop, while a condition that lets the index go too far gives you an exception.

Is Exception on the AP Computer Science A exam?

Exceptions are mostly an MCQ concept. Typical stems give you a code segment and ask "which of these will NOT throw an exception when executed?" or hand you an ArrayList traversal and ask what happens. Your job is to trace the code and check three things: do the indexes stay in bounds, could any reference be null, and is the list being modified during an enhanced for loop? Practice questions love the ArrayList-removal trap, where calling remove inside an enhanced for loop throws a ConcurrentModificationException, and the related indexed-loop trap where removing an element shifts everything left and skips the next item (no exception, just a logic bug, and the exam wants you to know the difference). On FRQs, like the 2021 MemberInfo question that has you remove members from a list, exceptions matter defensively. You earn points by writing traversal code that never goes out of bounds, often by looping backward or adjusting the index after a removal.

Exception vs Error

In Java, both Exception and Error represent problems at runtime, but they're different branches of the Throwable family. Exceptions are conditions a program could reasonably anticipate and recover from, like a bad index or a null reference. Errors are serious failures outside your program's control, like running out of memory or a StackOverflowError from runaway recursion. For AP CSA, the things you predict and explain in code are exceptions. Casual use of "error" to mean "my code broke" is fine in conversation, but on the exam, know that an out-of-bounds access throws an Exception, not an Error.

Key things to remember about Exception

  • An exception is a runtime event that interrupts normal program flow, like accessing index 5 in a list of size 3.

  • AP CSA tests your ability to predict when exceptions are thrown; you never write try-catch blocks on the exam.

  • Valid indexes run from 0 to length - 1 for arrays and 0 to size() - 1 for ArrayLists, so a loop condition with <= length almost always throws IndexOutOfBoundsException.

  • Removing an element from an ArrayList inside an enhanced for loop throws ConcurrentModificationException, while doing it in an indexed loop skips elements instead of throwing.

  • The four exceptions to know cold are ArrayIndexOutOfBoundsException, IndexOutOfBoundsException, NullPointerException, and ArithmeticException (integer division by zero).

  • Exceptions happen at runtime, not compile time, so code that compiles cleanly can still crash.

Frequently asked questions about Exception

What is an exception in AP Computer Science A?

An exception is an event at runtime that interrupts the normal flow of a Java program, such as accessing an out-of-bounds index, dividing an integer by zero, or calling a method on a null reference. If unhandled, it stops the program with an error message.

Do I need to know try-catch for the AP CSA exam?

No. The AP CSA exam does not test writing try-catch blocks or custom exception classes. It tests whether you can read code and identify when and why an exception would be thrown.

What's the difference between an exception and an error in Java?

Exceptions are runtime problems a program could anticipate, like IndexOutOfBoundsException or NullPointerException. Errors, like OutOfMemoryError, are serious system-level failures. Everything AP CSA tests falls on the exception side.

Does removing from an ArrayList in a loop always throw an exception?

No, it depends on the loop. Removing during an enhanced for loop throws a ConcurrentModificationException, but removing during an indexed for loop usually doesn't throw anything. Instead it shifts elements left and silently skips the next one, which is a logic bug the exam loves to test.

What exceptions do I need to know for AP CSA?

Know ArrayIndexOutOfBoundsException (bad array index), IndexOutOfBoundsException (bad ArrayList index), NullPointerException (using a null reference), ArithmeticException (integer division by zero), and ConcurrentModificationException (modifying an ArrayList during an enhanced for loop).