Java Reference
In-Depth Information
Trying
catches
tryBody
final
StmtList
StmtList
. . .
. . .
Catching
Figure 9.24: Abstract Syntax Tree for a Try Statement
Catching
catchIdDecl
catchBody
more
StmtList
. . .
CatchIdDeclaring
type
Catching
ident
Figure 9.25: Abstract Syntax Tree for a Catch Block
finally statements are analyzed. Semantic analysis of the catch clauses is
defined at Marker 30 .
Catch clauses require careful analysis. Each clause introduces a new iden-
tifier, the parameter of the clause. This identifier must be declared as an
exception (of class Throwable or a subclass of it). The parameter is made local
to the body of the catch clause by opening, and later closing, a new name
scope.
Using method
, defined in Figure 9.27, we verify
that the current catch clause does not ”hide” later catches. This is a reachability
issue—some exception type must be able to reach, and activate, each of the
catch clauses in a try statement.
Throws analysis for try statements is defined in Figure 9.28 at Marker 32 .
Catch clauses and finally statements are visited to collect the exceptions they
might throw. Before the try body is analyzed, we must include the exception
types declared in the try's catch clauses. We maintain a ”catch list” containing
all exception types potentially handled by enclosing try blocks. At the start
of analysis for a method or constructor, this list is null. Assume the method
get
subsumes
L
ater
C
atches
gives us the current catch list. Before updating the catch list
to include exceptions in the current catch clauses, we save the current catch
list into currentCatchList .Thecallto
C
atch
L
ist
adds exceptions in the
current catch clauses to the catch list. Now the try body can be analyzed.
After its analysis, the catch list is restored using
update
C
atch
L
ist
set
C
atch
L
ist
.Oncewe
Search WWH ::




Custom Search