-
Book Overview & Buying
-
Table Of Contents
OCA: Oracle Certified Associate Java SE 8 Programmer I Study Guide: Exam 1Z0-808
By :
try StatementNow that you know what exceptions are, let's explore how to handle them. Java uses a try statement to separate the logic that might throw an exception from the logic to handle that exception. Figure 6.2 shows the syntax of a try statement.
Figure 6.2 The syntax of a try statement
The code in the try block is run normally. If any of the statements throw an exception that can be caught by the exception type listed in the catch block, the try block stops running and execution goes to the catch statement. If none of the statements in the try block throw an exception that can be caught, the catch clause is not run.
You probably noticed the words “block” and “clause” used interchangeably. The exam does this as well, so we are getting you used to it. Both are correct. “Block” is correct because there are braces present. “Clause” is correct because they are part of a try statement.
There aren't a ton...
Change the font size
Change margin width
Change background colour