Flash cards
Review the key moves
What is the main idea behind Java try Keyword?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
Which statement best captures the main point of this lesson?
Complete the missing token from the example code.
___[] myNumbers = {1, 2, 3};Put the learning moves in the order that makes the concept easiest to apply.
❮ Java Keywords
Example
try {
int[] myNumbers = {1, 2, 3};
System.out.println(myNumbers[10]);
} catch (Exception e) {
System.out.println("Something went wrong.");
}Definition and Usage
The try keyword creates a try...catch statement.
The try statement allows you to define a block of code to be tested for errors while it is being executed.
The catch statement allows you to define a block of code to be executed, if an error occurs in the try block.
Related Pages
Read more about exceptions in our Java Try..Catch Tutorial .
❮ Java Keywords