Title: Key Concept - Try statement
Course: CPS 189: Java Certification - Review, Practice & Prepare (Development) > Section: Learning Modules

The try statement encloses a block of code that may generate an exception.

The try statement includes one or more catch blocks and an optional finally block.

Each catch block traps a different error type.

The finally block, if specified, runs whether an exception occurred or not.

try statement syntax:

try
{
<block>
}
catch (<exception-type-1> <exception-variable-1>)
{
<block>
}
catch (<exception-type-2> <exception-variable-2>)
{
<block>
}
…
catch (<exception-type-n> <exception-variable-n>)
{
<block>
}
finally
{
<block>
}

For additional study, view resources under:

- Level 1 Study Materials: Unit 11
- Level 1 Study Materials: Unit 12
- Level 2 Study Materials: Unit 1