Test 16 - Free Java SE 25 certification Mock test - Exam Code 1Z0-831-Oracle certified Java SE 25 Professional
Errors are an inevitable part of any program and the 1Z0-831 Java SE 25 Developer exam is designed to test your ability to predict how errors will propagate. This free 1Z0-831 mock exam is focused on try/catch/finally, the exception hierarchy and the rules the compiler enforces around checked and unchecked exceptions.
You start with the hierarchy. Throwable breaks down into Error and Exception and RuntimeException is under Exception as the root of the unchecked types. The questions then are which of the exceptions you must catch or declare (e.g. IOException) and which you don't need to (e.g. NullPointerException, ArithmeticException, ClassCastException). You'll also be asked why it's generally not a good idea to catch an Error and why StackOverflowError and OutOfMemoryError are in that category.
Catch ordering is a classic exam trap. If you have a catch block for a superclass appearing before a catch block for its subclass then the second catch block is unreachable and the code will not compile. You'll be practising the ability to spot this quickly as well as the related error of catching a checked exception that the try body can never throw. Multi-catch blocks have their own rules too in that the alternatives can't be related by inheritance and the catch parameter is implicitly final.
The finally block gets a lot of attention. It executes whether the try completes normally or via exception, even if the try contains a return statement. The examples of combining return values from try and finally illustrate how a return in the finally block will override the one in the try and quietly discard any exception in flight. You'll go through a number of these slowly, paying very close attention to the exact order of the printed messages. The only real ways of bypassing the finally block are via a call to System.exit or a fatal JVM failure.
Method overriding adds another layer. An overriding method cannot throw any checked exceptions broader than the one declared in the original method (though it can throw narrower or unchecked ones). Constructors, static initialisers and instance initialisers each have their own rules which you'll come across as well. Always check whether the question is asking about compilation or runtime.
Rethrowing and propagation are all over the place (how an uncaught exception terminates a thread and prints out a stack trace being the prime example). Each of the explanations shows you the sequence of control flow between the blocks so you can follow it yourself. Do the test, go through every mistake and for the difficult questions in particular, just sketch out the execution flow on a piece of paper.
